[R] Loading data from folder
maltaweel at anl.gov
Mon Feb 1 04:17:57 CET 2010
Hi, looks like the list.files() method was the key to my problem. With
that, I was able to just loop through the "files" variable and get the
file names to load
Thanks for your help.
On Jan 31, 2010, at 8:23 PM, jim holtman wrote:
> Something like the following might work. YOu can use 'choose.dir()'
> to get the directory:
> files <- list.files(path=yourDir)
> result <- do.call(rbind, lapply(files, read.csv))
> On Sun, Jan 31, 2010 at 9:10 PM, Mark Altaweel <maltaweel at anl.gov>
>> I am trying to load csv type data from a folder. However, rather than
>> syntax that simply loads one file at a time I was wondering if there
>> is a method that loads all data from a specific folder.
>> For instance, I have the following data files in a folder
>> ....etc. (245 total files in folder)
>> Each file has the following format:
>> Data1-5,Data 2-6,Data 3-7,...
>> Although the comma separated format is consistent file to file, the
>> name of the columns differ in many of the files.
>> What I want to do is simply load all that data by pointing to the
>> folder rather than specific file names.
>> I know this syntax: state.frame<-read.table("/nebraskaStats/",
>> header=T, sep=",") does not seem to read data from a folder but
>> it is intended to load specific files. I could write a loop that
>> iterates the number of the files (e.g., N-S-2009_N-T-2009, whereby
>> N,S, and T are iterated in the loop); however, this also seems
>> cumbersome. Anyway, is there a simple method that just loads all the
>> data in a folder rather than have to call out each specific file?
>> Thanks in advance. This has been a great board and I appreciate all
>> the past help.
>> [[alternative HTML version deleted]]
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> What is the problem that you are trying to solve?
More information about the R-help