Skip to content

Instantly share code, notes, and snippets.

@trcook
Created April 3, 2013 13:58
Show Gist options
  • Select an option

  • Save trcook/5301421 to your computer and use it in GitHub Desktop.

Select an option

Save trcook/5301421 to your computer and use it in GitHub Desktop.
String to Object Names with eval parse
paste("ds2$",names(ds2)[1],sep="")->x
eval(parse(text=(x))) # will output the contents of the object name constructed in x, in this case, it will output the individual names of all cases in a dataset.
# Here is an example of how you might use this:
#to create list of classes for vars in a data.frame:
sapply(names(ds2),function(x){
paste("ds2$",x,sep="")->y
class(eval(parse(text=(y))))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment