Thanks very much to all who answered my question yesterday on loops. Just a further quick question: If I have this: for(i in 1:n) { subset <- data[which(data$id==i),] which returns the rows where I have the variable ID=1, how can I tell the same statement to return just column Y where ID=i? I have tried this for(i in 1:n) { subset <- data[which(data$id==i),data$Y] but it doesn't work Thanks again Isabel __________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 31 Oct 2001, Isabel Jones wrote:> Thanks very much to all who answered my question > yesterday on loops. > > Just a further quick question: > > If I have this: > > for(i in 1:n) { > subset <- data[which(data$id==i),] > > which returns the rows where I have the variable ID=1, > how can I tell the same statement to return just > column Y where ID=i? > > I have tried this > > for(i in 1:n) { > subset <- data[which(data$id==i),data$Y]for(i in 1:n) { subset <- data[which(data$id==i),"Y"] maybe?> > but it doesn't work > > Thanks again > Isabel >*********************************************************************** Jens Nieschulze -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 31-Oct-01 Isabel Jones wrote:> If I have this: > > for(i in 1:n) { > subset <- data[which(data$id==i),] > > which returns the rows where I have the variable ID=1, > how can I tell the same statement to return just > column Y where ID=i?Try> subset <- data$Y[data$id==i]Cheers, Winfried ---------------------------------- E-Mail: Winfried Theis <theis at statistik.uni-dortmund.de> Date: 31-Oct-01 Time: 13:06:37 Dipl.-Math. Winfried Theis, Fachbereich Statistik, Graduiertenkolleg "Angewandte Statistik" Universität Dortmund, 44221 Dortmund Tel.: +49-231-755-5903 FAX: +49-231-755-4387 ---------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Isabel Jones <statsonthebrain at yahoo.com> writes:>Just a further quick question: > >If I have this: > >for(i in 1:n) { > subset <- data[which(data$id==i),] > >which returns the rows where I have the variable ID=1, >how can I tell the same statement to return just >column Y where ID=i?The subset() function does this: For(i in 1:n) { ss <- subset(data, id == i, Y) } Mark -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._