Re: [R] Combining many files into one

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 03 Nov 2008 21:36:03 -0500

The error message might mean that you have an empty file. It is probably better to use a list for reading in the data and then combine them at the end. "try" may also catch your errors:

all.dat <- lapply(list.files(mydir), function(.file){

    try(read.csv(.file))
})
all.dat <- do.call(rbind, all.dat)

On Mon, Nov 3, 2008 at 9:17 PM, t c <mudiver1200_at_yahoo.com> wrote:
> I have a few hundred .csv files in a folder on my hard drive, and I would like to combine them all into one file. They are all the same data, but the program that collected the data saved a file every 4 hours. I can combine the files one at a time using rbind, but am having a problem automating it in a for loop. The loop runs for a while, and finally gives an error message "no lines available in input". I would appreciate any help you can give. What I have so far is below. Thanks! Tim
>
>
> files<-list.files(mydir) #List of every file in the working directory
>
> for (i in 1:length(files)) #Loops through files
> {
> dat <- read.csv(files[i], header=T) #Reads one file at a time
> all.dat<-rbind(dat) #Binds the file just read to the end of all.dat
> }
>
>
>
>
> [[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.
>
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

______________________________________________
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.
Received on Tue 04 Nov 2008 - 02:40:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 04 Nov 2008 - 03:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive