Skip to content

How to convert a string to the column it represents in a dataframe, with a reproducible example

7 messages · David Winsemius, Bert Gunter, Nordlund, Dan (DSHS/RDA) +1 more

#
On Jan 17, 2013, at 1:36 PM, mtb954 at gmail.com wrote:

            
What is the goal of this effort?
#
On Jan 17, 2013, at 2:26 PM, mtb954 at gmail.com wrote:

            
You have not addressed the question ... why? Where are you going with this?
I would think that this is be best way to proceed:

x <- cars[ , "dist",  drop=FALSE]

Now "x" is a data.frame (and inherits from the list-class)  and names(x) will return "dist" and the usual access methods would work.
#
Inline below.

-- Bert
On Thu, Jan 17, 2013 at 3:02 PM, David Winsemius <dwinsemius at comcast.net> wrote:
... which, of course, begs the question: why bother. as you would do
the same with the original data frame.

-- Bert

  
    
#
Something like this

    eval(parse(text=y))

could be what you want. But even if it is, I am not sure it is what you should want.  Without more context, it is hard to say.

Hope this is at least somewhat helpful, 

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204