[R] loop with files
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Jun 24 12:07:52 CEST 2008
Alfredo Alessandrini wrote:
> I'm trying to make a loop with many files...
>
>
>
>> library(dplR)
>>
>> files <- system("ls *.rwl", intern=TRUE)
>>
>> files
>>
> [1] "cimfasy.rwl" "rocquce.rwl"
>
>> for (i in files) {a <- read.rwl(i,header=0)}
>>
> There are 70 series
> There are 21 series
>
>> class(a)
>>
> [1] "data.frame"
>
>
> This loop import all the files rwl in a single data.frame ( a ).
>
> Can I import a single files to a single data.frame? like this:
>
> for (i in files) {cimfasy <- read.rwl(i,header=0)}
>
> for (i in files) {rocquce <- read.rwl(i,header=0)}
>
>
>
not easy to get what you really want. the first loop above does read
each file separately and place it into a, but at each step it replaces
the content of a with a new one. so a contains only the content of the
last file, and the whole loop makes no sense.
the other two loops do quite the same, just that now you have additional
two variables filled with the contents of the same file, the last one on
your list. makes no sense either.
can you *explain* what the goal is?
vQ
More information about the R-help
mailing list