On 11/02/2009 05:04 PM, Steven Kang wrote:
Dear R users,
I wish to utilise processed and saved objects as arguments of a function.
Specifically, I have created objects using *"assign"*& *"paste"* functions
with an incremental index i, the names of the objects are:
fund1, fund2, fund3,....., fund80,..... (where the numerical value
increments according to the index i& class of these objects are dataframes)
I wish to collapse these objects row wisely using *"rbind"* function.
paste("fund", 1:i, sep = "") results in list of objects as characters...&
get(paste("fund", 1:i, sep = "")) outputs fund1...
Are there any methods to use these objects as an argument of "rbind" to
collapse the dataframes?
Your expertise in resolving this issue would be highly appreciated.
Hi Steven,
There is probably a neater way to construct the list of dataframes, but
this will probably do what you want:
dnames<-paste("fund",1:nfunds,sep="")
makelist<-function(x) {
nitems<-length(x)
newlist<-vector("list",nitems)
for(item in 1:nitems) newlist[[item]]<-get(x[item])
return(newlist)
}
dflist<-makelist(dfnames)
do.call("rbind",dflist)
Of course all of the dataframes must have the same number of columns or
the result will be messy or not there at all.
Jim
______________________________________________
R-help@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.