0

I have a quick question again. Could you help me in this case? I didn't find the solution with the Google/ Stackoverflow..

1) I have lot of CSV files

Example:

CSV 1

X DATE       VAR1  VAR2  VAR3 ...
1 1/5/06      1     2     3     
2 1/6/06      1     2     3     
3 1/7/06      3     4     5     
4 1/8/06      4     5     6 
...

CSV2

X DATE       VAR1  VAR2  VAR3 ...
1 1/8/06      1     2     3     
2 1/5/06      1     2     3     
3 1/9/06      3     4     5     
4 1/3/06      4     5     6 
...

And I have around 200 CSV files. In the CSV files, lot of duplications and more (I don't want to delete the duplications etc, I can't do..)

I would like to get a single data.frame or data.table. If I imported the CSV files, I got data tables from CSV files. I have a really bad solution which works with rows (that means, I split the data frames to rows and create a new "allcsv" data table). No so nice solution with for (i 1:n).

Maybe you have experience, and you can do it with a single line:

I would like to get it:

ALLCSV (collect all CSV file in a one file)

X DATE       VAR1  VAR2  VAR3 ...
1 1/5/06      1     2     3     
2 1/6/06      1     2     3     
3 1/7/06      3     4     5     
4 1/8/06      4     5     6 
1 1/8/06      1     2     3  #<–––– that is the new CSV    
2 1/5/06      1     2     3     
3 1/9/06      3     4     5     
4 1/3/06      4     5     6 
...                         #<----- CSV(..x)
RRR
  • 103
  • 1
  • 7

1 Answers1

1

I got the answer from Roman Lustrik (thanks the link!). The code coming here:

load_data <- function(path) { 
  files <- dir(path, pattern = '\\.csv', full.names = TRUE)
  tables <- lapply(files, read.csv)
  do.call(rbind, tables)
}

pollutantmean <- load_data("specdata")
RRR
  • 103
  • 1
  • 7