[R] Re ad in multiple datasets
Gabor Grothendieck
ggrothendieck at gmail.com
Sun Sep 27 15:46:27 CEST 2009
Try this:
filenames <- sprintf("data%d.csv", 1:20)
DFs <- sapply(filenames, read.csv, simplify = FALSE)
which will return a list of data frames, DFs, each named by its
filename so that DFs[[1]] or DFs[["data1.csv"]] give the data frame
read from data1.csv, etc. and names(DFs) gives a vector of their names
as does filenames.
On Sat, Sep 26, 2009 at 11:47 PM, legen <legendy at gmail.com> wrote:
>
> Hello, all:
>
> I have twenty datasets named as: data1.csv, data2.csv, …, data20.csv. I am
> trying to read all of them into R by using loop and function read.table(),
> but I don't know how to handle the name of datasets. Has anybody have
> encountered a similar problem? Or do you have any suggestions? Your help
> would be greatly appreciated.
>
> Legen
>
> --
> View this message in context: http://www.nabble.com/Read-in-multiple-datasets-tp25630688p25630688.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.
>
More information about the R-help
mailing list