Re: [R] Simple R Question...

From: Jeff Newmiller <jdnewmil_at_dcn.davis.ca.us>
Date: Sat, 21 May 2011 05:00:51 -0700

Or

dd[,myname]

should work too.

If you are worried about getting multiple columns, you can just make myname a vector of column names using c() before you use either Jim's list indexing or the above matrix indexing syntax.



Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil_at_dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k

Sent from my phone. Please excuse my brevity.

Jim Holtman <jholtman_at_gmail.com> wrote:

dd[[ myname]] Sent from my iPad On May 21, 2011, at 7:37, Lars Bishop <lars52r_at_gmail.com> wrote: > Let's say I have the data frame 'dd' below. I'd like to select one > column from this data frame (say 'a') and keep its name in the > resulting data frame. That can be done as in #2. However, what if I > want to make my selection based on a vector of names (and again keep > those names in the resulting data frame). My attempt is #4 but doesn't > work. > > dd <- data.frame(a = gl(3,4), b = gl(4,1,12), c=rnorm(12)) #1 > data.frame("a" = dd[,"a"]) #2 > > mynames <- "a" #3 > data.frame(eval(mynames) = dd[, mynames]) #4 > > thanks, > Lars. > >_____________________________________________

> 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.

        [[alternative HTML version deleted]]



R-help_at_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. Received on Sat 21 May 2011 - 12:02:59 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 21 May 2011 - 13:10:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive