Created
April 3, 2013 13:58
-
-
Save trcook/5301421 to your computer and use it in GitHub Desktop.
String to Object Names with eval parse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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