[R] Help with IF command strings
arun
smartpink111 at yahoo.com
Fri Jul 12 03:21:01 CEST 2013
HI,
Try this:
set.seed(485)
dat1<- as.data.frame(matrix(sample(0:10,26*10,replace=TRUE),ncol=26))
mean(dat1$V21[dat1$V2==1|dat1$V2==0])
#[1] 3.8
#or
with(dat1,mean(V21[V2==1|V2==0]))
#[1] 3.8
A.K.
I have data in 26 columns, I'm trying to get a mean for column 21 only for the participants that are either 0 or 1 in column 2.
One of the commands I tried looked something like this
mean(data1$V21, if(V2 = 1))
So basically I need to have the program run a mean (and later
other forms of analysis) on participants based on their condition.
either 0 or 1.
Help is greatly appreciated.
Thanks
More information about the R-help
mailing list