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@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. ______________________________________________ R-help@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.