[R] Using variable names in data frame
Emmanuel Paradis
paradis at isem.univ-montp2.fr
Fri Dec 22 10:15:48 CET 2000
At 14:49 22/12/00 +1100, M.McStephen at papyrus.mhri.edu.au wrote:
>Hi All,
>
>I'm trying to use the names from a data frame to display data in the
>frame:
>
>> data.n<-names(data) # put names into a vector called data.n
>data.n[1]
>[1] "ID"
>
>>
>> paste("data$",data.n[1],sep="") # create the name of the column in
>the dataframe
>[1] "data$ID"
>
>> as.symbol(paste("data$",data.n[1],sep=""))
>data$ID
>
>> eval(as.symbol(paste("data$",data.n[1],sep="")))
>Error in eval(expr, envir, enclos) : Object "data$ID" not found
>>
>
>I want to be able to list the contents of data$ID by using data.n[1]
>just as I would by typing data$ID at the > prompt.
Maybe what you want is:
eval(parse(text=paste("data$",data.n[1],sep="")))
Emmanuel Paradis
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list