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

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Fri Jan 18 00:15:13 CET 2013


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of mtb954 at gmail.com
> Sent: Thursday, January 17, 2013 2:27 PM
> To: David Winsemius; r-help at r-project.org
> Subject: Re: [R] How to convert a string to the column it represents in
> a dataframe, with a reproducible example
> 
> Hi David,
> 
> I would like to have two objects, one containing the values in a column
> and
> the other containing the column's name.
> 
> Of course, that's easy to do manually, but I don't want to have to type
> out
> the name of the column more than once (thus, below, I have typed it
> once in
> quotes, and I am trying to find a programatic way to create the other
> object, without typing the column name again).
> 
> Thank you for your help.
> 
> Mark Na
> 

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




More information about the R-help mailing list