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

Marc Moragues marc.moragues at gmail.com
Thu Apr 10 11:18:42 CEST 2008



Xin <jasonshi510 <at> 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.



More information about the R-help mailing list