Displaying 20 results from an estimated 10000 matches similar to: "Converting data frame to symmetric matrix"
2013 Dec 14
2
Change factor levels
Suppose I have a dataframe 'd' defined as
L3 <- LETTERS[1:3]
d0 <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace
= TRUE))
(d <- d0[d0$fac %in% c('A', 'B'),])
x y fac
2 1 2 B
3 1 3 A
4 1 4 A
5 1 5 A
6 1 6 B
8 1 8 A
Even though factor 'fac' in 'd' only has 2 levels, but it seems to bear the
birthmark
2005 Jun 10
4
data.frame to character
Hi,
Excuse me for this simple question.
How to convert as.data.frame to as.character?
?data.frame
> L3 <- LETTERS[1:3]
> L10 <- LETTERS[1:10]
> d <- data.frame(cbind(x=c("XYZ"), y=L10), fac=sample(L3, 10, repl=TRUE))
> d
x y fac
1 XYZ A A
2 XYZ B A
3 XYZ C A
4 XYZ D A
5 XYZ E B
6 XYZ F C
7 XYZ G A
8 XYZ H C
9 XYZ I B
10 XYZ
2006 Jan 23
1
Sample rows in data frame by subsets
Hi,
I need to resample rows in a data frame by subsets
L3 <- LETTERS[1:3]
d <- data.frame(cbind(x=1, y=1:10), fac=sample(L3, 10, repl=TRUE))
x y fac
1 1 1 A
2 1 2 A
3 1 3 A
4 1 4 A
5 1 5 C
6 1 6 C
7 1 7 B
8 1 8 A
9 1 9 C
10 1 10 A
I have seen this used to sample rows with replacement
d[sample(nrow(d), replace=T), ]
x y fac
7 1 7 B
2
2006 Apr 06
3
convert a data frame to matrix - changed column name
I have a question, which very easy to solve, but I can't find a solution.
I want to convert a data frame to matrix. Here my toy example:
> L3 <- c(1:3)
> L10 <- c(1:6)
> d <- data.frame(cbind(x=c(10,20), y=L10), fac=sample(L3, + 6, repl=TRUE))
> d
x y fac
1 10 1 1
2 20 2 1
3 10 3 1
4 20 4 3
5 10 5 2
6 20 6 2
> is.data.frame(d)
[1] TRUE
> sapply(d,
2012 Jun 07
3
conditional statement to replace values in dataframe with NA
Hello and thanks for helping.
#some data
L3 <- LETTERS[1:3]
dat1 <- data.frame(cbind(x=1, y=rep(1:3,2), fac=sample(L3, 6, replace=TRUE)))
#When x==1 and y==1 I want to replace the 1 values with NA
#I can select the rows I want:
dat2<-subset(dat1,x==1 & y==1)
#replace the 1 with NA
dat2$x<-rep(NA,nrow(dat2)
dat2$y<-rep(NA,nrow(dat2)
#select the other rows and rbind
2006 Sep 27
1
Impossible to merge with a zero rows data frame?
I'm trying to merge two data frames. One of them is a zero rows data
frame.
I'm using the merge parameter 'all.x = TRUE' so I'd expect to obtain all
the rows of x. In fact the merge help says:
all.x: logical; if 'TRUE', then extra rows will be added to the
output, one for each row in 'x' that has no matching row in
'y'. These rows
2008 Apr 22
3
how to read in multiple files with unequal number of columns
Dear all,
I want to read in 1000 files which contain varying number of columns.
For example:
file[1] contains 8 columns (mixture of characters and numbers)
file[2] contains 16 columns etc
I'm reading everything into one big data frame and when I try rbind, R
returns an error of
"Error in rbind(deparse.level, ...) :
numbers of columns of arguments do not match"
Below is my
2007 May 11
1
changing the mode of a factor (PR#9675)
Full_Name: Fr?d?ric Gosselin
Version: 2.5 vs 2.4 and 2.2.1
OS: windows XP
Submission from: (NULL) (195.221.118.52)
#############
L3 <- LETTERS[1:3]
(d <- data.frame(cbind(x=1, y=1:10), fac=as.factor(sample(L3, 10,
repl=TRUE))))
mode(d[,3])<-"numeric"
###############
when trying to change the mode of a column in a data.frame that is a factor to
numeric(cf. preceding code),
2009 May 26
1
Bug in "$<-.data.frame" yields corrupt data frame (PR#13724)
Full_Name: Steven McKinney
Version: 2.9.0
OS: Mac OS X 10.5.6
Submission from: (NULL) (142.103.207.10)
A corrupt data frame can be constructed as follows:
foo <- matrix(1:12, nrow = 3)
bar <- data.frame(foo)
bar$NewCol <- foo[foo[, 1] == 4, 4]
bar
lapply(bar, length)
> foo <- matrix(1:12, nrow = 3)
> bar <- data.frame(foo)
> bar$NewCol <- foo[foo[, 1] == 4, 4]
2002 Aug 15
1
EXT3 crash
Hi all. I am running the 2.4.18-3smp kernel and over the poast couple of
days, ext3 has been crashing. Here is the output:
Assertion failure in journal_commit_transaction() at commit.c:535:
"buffer_jdirty(bh)"
------------[ cut here ]------------
kernel BUG at commit.c:535!
invalid operand: 0000
loop autofs nfs lockd sunrpc 3c59x ns83820 ide-scsi ide-cd cdrom usb-uhci usbc
CPU: 0
2005 Mar 31
1
Contingency table: logistic regression
Hi,
I am analyzing a data set with greater than 1000 independent cases
(collected in an unrestricted manner), where each case has 3 variables
associated with it: one, a factor variable with 0/1 levels (called XX),
another factor variable with 8 levels (X) and a third response variable
with two levels (Y: 0/1). I am trying to see if X1 has an effect on the
relationship between X2 and the
2009 Nov 05
2
[LLVMdev] Strange error for libLLVMCore.a
mingw, llvm 2.6 (buid with llvm-gcc)
Example source code:
http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html
I change
LLVMCreateJITCompiler(&engine, provider, &error);
to
LLVMCreateJITCompiler(&engine, provider, 3, &error);
$ llvm-gcc `llvm-config --cflags` -c fac.c
$ g++ `llvm-config --libs --cflags --ldflags core analysis
executionengine jit
2009 Jun 03
1
Need help understanding output from aov and from anova
Hi all,
I noticed something strange when I ran aov and anova.
vtot=c(7.29917, 7.29917, 7.29917) #identical values
fac=as.factor(c(1,1,2)) #group 1 has first two elements, group 2 has
the 3rd element
When I run:
> anova(lm(vtot~fac))
Analysis of Variance Table
Response: vtot
Df Sum Sq Mean Sq F value Pr(>F)
fac 1 1.6818e-30 1.6818e-30 0.3333 0.6667
Residuals 1
2012 May 29
1
GAM interactions, by example
Dear all,
I'm using the mgcv library by Simon Wood to fit gam models with interactions and I have been reading (and running) the "factor 'by' variable example" given on the gam.models help page (see below, output from the two first models b, and b1).
The example explains that both b and b1 fits are similar: "note that the preceding fit (here b) is the same as
2013 Jan 17
3
Colors in interaction plots
Hi,
I am trying to plot an interaction.plot with different color for each
level of a factor. It has an erratic behavior.
For example, it works for the first interaction.plot below, with the
example from the ALDA book, but not with the other plots, from the NPK
dataset:
# from http://www.ats.ucla.edu/stat/r/examples/alda/ch2.htm
tolerance <-
2011 Jan 21
1
match function causing bad performance when using table function on factors with multibyte characters on Windows
[I originally posted this on the R-help mailing list, and it was suggested that R-devel would be a better
place to dicuss it.]
Running ?table? on a factor with levels containing non-ASCII characters
seems to result in extremely bad performance on Windows. Here?s a simple
example with benchmark results (I?ve reduced the number of replications to
make the function finish within reasonable time):
2010 Apr 21
5
Bugs? when dealing with contrasts
R version 2.10.1 (2009-12-14)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with
2002 May 13
1
GLM questions
Hi
I'm doing a glm analysis and I have two doubts (at least :)
1) When I run the function it gives a lot of warnings (see below) what
they mean ? (may be I'm ignorant about this analysis ...)
glm.poisson<-glm(log(Jkij+1)~fac.ano+fac.tri+fac.icesr+fac.mat+fac.ano:fac.icesr+fac.ano:fac.tri,family=poisson())
warnings()
40: non-integer x = 1.252763
41: non-integer x = 1.864785
42:
2009 May 22
1
regrouping factor levels
Hi all,
I had some trouble in?regrouping factor levels for a variable. After some experiments, I have figured out how I can recode to modify the factor levels. I would now like some help to understand why some methods work and others don't.
Here's my code :
rm(list=ls())
###some trials in recoding factor levels
char<-letters[1:10]
fac<-factor(char)
levels(fac)
print(fac)
##first
2009 Jul 31
2
how use the subset?
hi ,everyone
I want subtract some dataset by subset.
>From the help running help(subset), ths information is "*subset(airquality,
Day == 1, select = -Temp)* "
while I running my script written as "*g1data<-subset(errdata, fac>12) *"
,it is wrong with the error information "*subset.default(newerrdata,
fac>12),can not find fac*"
and g1 in read