[R] Looping through R objects

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Jul 28 23:12:22 CEST 2009


Hi,

On Jul 28, 2009, at 4:54 PM, Vivek Ayer wrote:

> Hi all,
>
> I have 13 csv files and I want to assign each csv file to one  
> object, i.e.,
>
> bc1 <- read.csv("1.csv,header=TRUE,sep="")
> bc2 <- read.csv("2.csv,header=TRUE,sep="")
> bc3 ...
>
> So I want to create 13 objects. How could I automate this with a for  
> loop?
>
> for (i in c(1:13)) ...
>
> Any ideas?


objects <- lapply(1:13, function(i) {
   read.csv(paste(i, 'csv', sep='.'), header=TRUE, sep="")
})

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list