[R] Iterate over a list of input files?
Tsjerk Wassenaar
tsjerkw at gmail.com
Wed Feb 9 06:23:27 CET 2011
Hi Mark,
If you have a function that, for a given file name, returns the data
in the way you want, then you can use 'dir' or 'paste' to generate a
list of names, which you can read in in one go with apply:
my_read <- function(filename)
{
...
}
filenames <- dir(directory,pattern)
filenames <- paste(...)
data <- apply(filenames, my_read)
Hope it helps,
Tsjerk
On Wed, Feb 9, 2011 at 1:50 AM, dunner <ross.dunne at tcd.ie> wrote:
>
> Quick and dirty answer:
>
> Try ?paste in conjunction with a "for" loop which iterates over
> i:length(Files), and you can paste "i" onto the end of your filename, then
> add the data to cd=list(), cd[i], then "unlist" the data or
> as.data.frame(cd).
>
> I'm sure there are more elegant alternatives.
>
> Ross
> --
> View this message in context: http://r.789695.n4.nabble.com/Iterate-over-a-list-of-input-files-tp3285285p3288088.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>
--
Tsjerk A. Wassenaar, Ph.D.
post-doctoral researcher
Molecular Dynamics Group
* Groningen Institute for Biomolecular Research and Biotechnology
* Zernike Institute for Advanced Materials
University of Groningen
The Netherlands
More information about the R-help
mailing list