[R] Reading a bunch of csv files into R

Bryan Hanson hanson at depauw.edu
Fri May 25 20:57:39 CEST 2012


HJ, try something like this:

   files <- list.files(pattern = "\\.(csv|CSV)$")

    for (i in 1:length(files)) {
            temp <- read.csv(files[i], header = FALSE)
 ... do whatever you want with the contents of temp...
    }

Bryan
***********
Bryan Hanson
Professor of Chemistry & Biochemistry
DePauw University

On May 25, 2012, at 1:16 PM, HJ YAN wrote:

> Dear R users
> 
> 
> I am struggling from a data importing issue:
> 
> I have some hundreds of csv files needed to be read into R for futher
> analysis. All those csv files are named in one of the three formats:
> 
> (1) strings: e.g. London_Oxford street
> (2) Integer: e.g. 1234_5678
> (3) combined: e.g. London_1234
> 
> I intend to use read.csv("xxxx_xxx.csv") but I only dealt with
> sigle documents before and if there are only no more than 20 files, I do
> not bother to search a more efficient way.
> 
> 
> Is there any claver way that I do not have to type in all these hundreds
> names by hand, maybe using a R package or write some code in some other
> languages if it is not too difficult to learn.
> 
> Any thoughts/hints please??
> 
> Many thanks in advance!
> 
> HJ
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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