[R] Stumped with subsetting
sundar.dorai-raj at PDF.COM
Thu Jul 29 21:36:22 CEST 2004
Peter Wilkinson wrote:
> This seems like such a trivial thing to do:
> given a data.frame DF and variables w,v, x,y,z I can do
> DF["x"] or DF[c("x","y")]
> if I create a vector, mylist = c("x",y")
> then I do DF[mylist]
> I am not getting x and y, I get something else.
> what is the correct way to subset a data.frame by columns using a
> vector, as if I were doing DF["x","y"]?
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide!
You want DF[, mylist]. DF[mylist] returns a list. You may want to look
at "An Introduction to R", which covers this topic.
P.S. Please create a new e-mail when posting to the list rather than
replying to a message and just changing the subject. This is (of course)
covered in the posting guide.
More information about the R-help