[R] loop with files

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Jun 24 12:37:44 CEST 2008


Alfredo Alessandrini wrote:
>> can you *explain* what the goal is?
>>     
>
> I want import any rwl files (cimfasy.rwl, rocquce.rwl, .......),  in a
> data.frame with the name like to name of file rwl:
>
> cimfasy.rwl -> cimfasy
>
> rocquce.rwl -> rocquce
>
> with this loop:
>
>   
>> library(dplR)
>>
>> files <- system("ls *.rwl", intern=TRUE)
>>
>> files
>>     
> [1] "cimfasy.rwl" "rocquce.rwl"
>   
>> for (i in files) {a <- read.rwl(i,header=0)}
>>     

for (file in files)
    assign(gsub("\\.rwl$", "", file), read.rwl(file, header=0))

?assign
?gsub

vQ



More information about the R-help mailing list