An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130117/da781ee8/attachment.pl>
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:
Hello R-helpers, I have run the following lines of code: x<-"cars$dist" y<-noquote(x) Now y is a string containing the characters "cars$dist" My question....is there an R function (or combination of functions) that I can apply to y that will cause y to contain the numbers in cars$dist? Even better, can I do it without using noquote()?
What is the goal of this effort?
David Winsemius Alameda, CA, USA
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130117/40f6b166/attachment.pl>
On Jan 17, 2013, at 2:26 PM, mtb954 at gmail.com wrote:
Hi David, I would like to have two objects, one containing the values in a column and the other containing the column's name.
You have not addressed the question ... why? Where are you going with this?
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).
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.
David. > > Thank you for your help. > > Mark Na > > > On Thu, Jan 17, 2013 at 4:06 PM, David Winsemius <dwinsemius at comcast.net> wrote: > > On Jan 17, 2013, at 1:36 PM, mtb954 at gmail.com wrote: > > > Hello R-helpers, > > > > I have run the following lines of code: > > > > x<-"cars$dist" > > y<-noquote(x) > > > > > > Now y is a string containing the characters "cars$dist" > > > > My question....is there an R function (or combination of functions) that I > > can apply to y that will cause y to contain the numbers in cars$dist? Even > > better, can I do it without using noquote()? > > What is the goal of this effort? > > -- > > David Winsemius > Alameda, CA, USA > > David Winsemius Alameda, CA, USA
Inline below. -- Bert
On Thu, Jan 17, 2013 at 3:02 PM, David Winsemius <dwinsemius at comcast.net> wrote:
On Jan 17, 2013, at 2:26 PM, mtb954 at gmail.com wrote:
Hi David, I would like to have two objects, one containing the values in a column and the other containing the column's name.
You have not addressed the question ... why? Where are you going with this?
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).
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.
... which, of course, begs the question: why bother. as you would do the same with the original data frame. -- Bert
-- David.
Thank you for your help. Mark Na On Thu, Jan 17, 2013 at 4:06 PM, David Winsemius <dwinsemius at comcast.net> wrote: On Jan 17, 2013, at 1:36 PM, mtb954 at gmail.com wrote:
Hello R-helpers, I have run the following lines of code: x<-"cars$dist" y<-noquote(x) Now y is a string containing the characters "cars$dist" My question....is there an R function (or combination of functions) that I can apply to y that will cause y to contain the numbers in cars$dist? Even better, can I do it without using noquote()?
What is the goal of this effort? -- David Winsemius Alameda, CA, USA
David Winsemius Alameda, CA, USA
______________________________________________ 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.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
-----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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130118/1e841760/attachment.pl>