Re: [R] Stumped with subsetting

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Fri 30 Jul 2004 - 05:36:22 EST

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"]?
>
> Peter
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

You want DF[, mylist]. DF[mylist] returns a list. You may want to look at "An Introduction to R", which covers this topic.

--sundar

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.



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jul 30 05:42:03 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:41:20 EST