[R] how to read data from table based a condition
Uwe Ligges
ligges at statistik.tu-dortmund.de
Thu Apr 10 11:26:14 CEST 2008
Marc Moragues wrote:
>
> 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])
Folks, please!
1. If you answer, please write at least syntactically valid code (look
at your index brackets).
Just
mean(y[x==1])
should do the trick....
2. It is a bad idea to do others' homeworks, they won't learn much this way.
Best wishes,
Uwe Ligges
> You can also look at ?subset.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list