[R] How to read many files at one time?
Don MacQueen
macq at llnl.gov
Mon Jul 16 16:35:08 CEST 2007
Storing them as elements of list is fine, but if you want them as
individual objects, then something like this (not tested):
for (i in seq( length(tst) ) ) {
tmp <- read.table( tst[i] ) ## or read.delim() or read.csv(),
as necessary
assign( data.name[i], tmp )
}
-Don
At 3:16 PM -0600 7/14/07, Zhang Jian wrote:
>I want to load many files in the R. The names of the files are "Sim1.txt", "
>Sim2.txt", "Sim3.txt", "Sim4.txt", "Sim5.txt" and so on.
>Can I read them at one time? What should I do? I can give the same names in
>R.
>Thanks.
>
>For example:
>> tst=paste("Sim",1:20,".txt",sep="") # the file names
>> tst
> [1] "Sim1.txt" "Sim2.txt" "Sim3.txt" "Sim4.txt" "Sim5.txt" "Sim6.txt"
> [7] "Sim7.txt" "Sim8.txt" "Sim9.txt" "Sim10.txt" "Sim11.txt" "Sim12.txt"
>[13] "Sim13.txt" "Sim14.txt" "Sim15.txt" "Sim16.txt" "Sim17.txt" "Sim18.txt"
>[19] "Sim19.txt" "Sim20.txt"
>
>> data.name=paste("Sim",1:20,sep="") # the file names in R
>> data.name
> [1] "Sim1" "Sim2" "Sim3" "Sim4" "Sim5" "Sim6" "Sim7" "Sim8" "Sim9"
>[10] "Sim10" "Sim11" "Sim12" "Sim13" "Sim14" "Sim15" "Sim16" "Sim17" "Sim18"
>[19] "Sim19" "Sim20"
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at stat.math.ethz.ch 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.
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
More information about the R-help
mailing list