[R] How to fill out some columns?

2008-04-11 Thread Jorge Velez
Dear R users, I'm working with 2 data sets which look like (for example) dx and dy in the next code: # Seed set.seed(4) # First data frame dx=matrix(rnorm(6*5),ncol=6) colnames(dx)=LETTERS[1:6] # Second data frame dy=matrix(rnorm(3*5),ncol=3) colnames(dy)=c('A','C','E') As you will notice,

Re: [R] how to check if a variable is preferentially present in a sample

2008-04-08 Thread Jorge Velez
Hi Tania, I think it could be. I tried a solution based on your data set using a chi-squared approach. Here is what I got: # # Data set set.seed(123) d - data.frame(cbind(val=rnorm(1:10)^2, group=sample(LETTERS[1:5],100,repl=TRUE))) d[,val]-as.numeric(as.character(d$val)) #

Re: [R] Problem with NA data when computing standard error

2008-04-08 Thread Jorge Velez
Hi there, Perhaps se-function(x)sqrt(var(x,na.rm=T)/sum(!is.na(x))) object1-as.data.frame.table(tapply(Data[Year==1999],list(Group[Year==1999],Season[Year==1999]),mean)) object2-as.data.frame.table(tapply(Data[Year==1999],list(Group[Year==1999],Season[Year==1999]),se)) Hope this helps, Jorge

[R] Replacing text

2008-03-11 Thread Jorge Velez
Hi Luciana, Try this: yourData[,1] - sapply(yourData[,1], function(x){ x=as.character(x) x[which(x==Toyota2)]-Scion x } ) # Example set.seed(123) x=c(Jeep,Nissan, Toyota1, Toyota2) y=rnorm(4) DATA=data.frame(x,y) DATA x y 1Jeep -0.56047565 2 Nissan -0.23017749 3