Re: [R] how to read data from table based a condition

2008-04-10 Thread Uwe Ligges
Marc Moragues wrote: > > Xin hotmail.com> writes: > > >> y<-data[,7] >> x<-data[,3] >> >> I want to know the mean of y if corresponding x=1. >> > > Try this: > > mean(data[data[,3]==1,data[,7]) Folks, please! 1. If you answer, please write at least syntactically valid code (look at your

Re: [R] how to read data from table based a condition

2008-04-10 Thread Uwe Ligges
Xin wrote: > Dear All: > > I imported a table into R. But I want to read a variable (y) from this > table conditional on another variable (x=1) in the table. > > y<-data[,7] > x<-data[,3] > > I want to know the mean of y if corresponding x=1. > > I tried > > if (x==1) y3<-y > > It do

Re: [R] how to read data from table based a condition

2008-04-10 Thread Marc Moragues
Xin hotmail.com> writes: > > y<-data[,7] > x<-data[,3] > > I want to know the mean of y if corresponding x=1. > Try this: mean(data[data[,3]==1,data[,7]) You can also look at ?subset. __ R-help@r-project.org mailing list https://stat.ethz.ch/m

[R] how to read data from table based a condition

2008-04-10 Thread Xin
Dear All: I imported a table into R. But I want to read a variable (y) from this table conditional on another variable (x=1) in the table. y<-data[,7] x<-data[,3] I want to know the mean of y if corresponding x=1. I tried if (x==1) y3<-y It does not work. Anyone can give a help? Than