[R] Referring to an object by a variable containing its name: 6 failures

Eik Vettorazzi E.Vettorazzi at uke.de
Fri Sep 16 16:39:07 CEST 2011

maybe I did not get the point, but get() does exactly what you want:

whatIwant = 2
nomdeplume = "whatIwant"


Am 16.09.2011 16:09, schrieb Timothy Bates:
> On 16 Sep 2011, at 1:49 AM, andrewH wrote:
>>> I'm trying to make a function that takes column names then 
>>> using the variable colName, containing the name of
>>> the column,  to refer to the column itself
> rmailbox at justemail.net said
>> What am I missing about your inquiry: It seems like x[ , colName ] should work:
> I think what is being asked is to treat the value of a variable not as a string (which work fine in your example), but as a variable name
> In php you’d use $$ to dereference by name
> $whatIwant = 2
> $nomdeplume = "whatIwant"
> $$nomdeplume
> 2
> I’ve not come across this functionality in R: would be great if it exists
> ______________________________________________
> 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.

Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

More information about the R-help mailing list