Inherit names ...
On Wed, 20 Jan 1999, John Logsdon wrote:
No doubt an easy answer to this exists. I have a data frame which comprises 4 matrices and 2 vectors: year(1024,6),growth(1024,6),ycens(1024,6),gcens(1024,6),yinit(1024),ginit(1024) The names of the 26 columns get denoted as y.1 to y.6, g.1 to g.6, yc.1 to yc.6, gc.1 to gc.6, yi and gi as these are the internal names. I wish to make a subset of the data using the logical vector R1(length 1024) so that only the cases where R1 is TRUE are included. I can do this by: R1data<-alldata[R1]
R1data<-alldata[R1,] is what you want (note the comma)
(c) Is there a way within a data frame to refer conveniently to a group of columns (ie one of the constituent matrices in the case above)?
alldata[,c(1,3,5,11:20)]
would give the first, third, fifth, and eleventh through twentieth
columns, or you can refer to them by name: eg
alldata[,c("y.2","gc.4","gi")]
Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._