[R-sig-Epi] converting string to a object name of a dataset

Madan Gopal Kundu mgk4transweb at gmail.com
Fri Mar 18 06:18:55 CET 2011


Hi,

I am trying to access object which is variable of a dataset using
string.  For that I am trying to convert a string to the object name
in the following code. But unfortunately it looks something is going
wrong in the following code.

data1<- data.frame(x=c(1:4), y=rep(1:4))
gvars<- c("x", "y")
z<- paste("data1", gvars[1], sep="$")
get(z)

The above code should return following output:
[1] 1 2 3 4

but instead it is printing following error
"Error in get(z) : object 'data1$x' not found"

Please help me to fix the problem.

Regards
Madan



More information about the R-sig-Epi mailing list