Hi all, I have roughly fifty dataframes and a dataframe with the names of the fifty dataframes. I want to perform the same set of manipulations on all fifty dataframes, but can't find a way to batch process from a list with the dataframe names using a loop. Is there a way to read the file names from the dataframe with the names and then call the referenced dataframe? This would save me a lot of typing. Thanks for any help, Wade [[alternative HTML version deleted]]
Wade, from your description it is not clear to me whether you have fifty _R objects_ or fifty files containing tables (i.e. data frames). If the former, you can do something like a <- data.frame(1:10) b <- data.frame(10:1) c <- data.frame(letters[1:20]) my.data.frames <- data.frame( name=c("a", "b", "c") ) all.data <- lapply(as.character(my.data.frames$name), get) and then all.data contains all your data frames, you can use a loop or 'lapply' to manipulate them. If the data frames are in the file, then you can do something like this: all.data <- lapply(as.character(my.data.frames$name), read.table, header=TRUE) Other options to read.table can be added after 'header=TRUE'. Is this something you wanted? Best, Gabor On Sun, Oct 26, 2008 at 9:10 PM, Wade Wall <wade.wall at gmail.com> wrote:> Hi all, > > I have roughly fifty dataframes and a dataframe with the names of the fifty > dataframes. I want to perform the same set of manipulations on all fifty > dataframes, but can't find a way to batch process from a list with the > dataframe names using a loop. Is there a way to read the file names from > the dataframe with the names and then call the referenced dataframe? This > would save me a lot of typing. > > Thanks for any help, > > Wade > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Gabor Csardi <Gabor.Csardi at unil.ch> UNIL DGM
I think you need to be a bit more specific on this one. What is the format of your data.frames? On disk or actually in your workspace? Example code would also help. Even psuedo code describing what you want to do. Regards, Kaom On Oct 26, 2008, at 1:10 PM, Wade Wall wrote:> Hi all, > > I have roughly fifty dataframes and a dataframe with the names of > the fifty > dataframes. I want to perform the same set of manipulations on all > fifty > dataframes, but can't find a way to batch process from a list with the > dataframe names using a loop. Is there a way to read the file names > from > the dataframe with the names and then call the referenced > dataframe? This > would save me a lot of typing. > > Thanks for any help, > > Wade > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
You might want to have a look at the plyr package - http://had.co.nz/plyr. The intro pdf describes a couple of problems that are similar to yours. Hadley On Sun, Oct 26, 2008 at 3:10 PM, Wade Wall <wade.wall at gmail.com> wrote:> Hi all, > > I have roughly fifty dataframes and a dataframe with the names of the fifty > dataframes. I want to perform the same set of manipulations on all fifty > dataframes, but can't find a way to batch process from a list with the > dataframe names using a loop. Is there a way to read the file names from > the dataframe with the names and then call the referenced dataframe? This > would save me a lot of typing. > > Thanks for any help, > > Wade > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- http://had.co.nz/