I have a directory containing about 2000 .csv files.
Each file has the following structure (showing 4 out of 500 lines):
Date;QOF
1 2004-01-04 - 2004-01-10;9
2 2004-01-11 - 2004-01-17;11
3 2004-01-18 - 2004-01-24;13
4 2004-01-25 - 2004-01-31;13
The "QOF" column is also the name of the .csv file, and each file has a unique name (for example, "MSTF", "XQS", etc.). I would like this column from each .csv file to be combined into the first CSV file read, which also contains a date variable. In other words, I want to save all columns from the first file and merge only the second column from all other CSV files into this file. The end result should look something like this:
Date;QOF;MSTF;XQS
1 2004-01-04 - 2004-01-10;9;10;8
2 2004-01-11 - 2004-01-17;11;11;5
3 2004-01-18 - 2004-01-24;13;31;2
4 2004-01-25 - 2004-01-31;13;45;23
So far I have tried this:
filenames <- list.files()
do.call("cbind", lapply(filenames, read.csv, header = TRUE))
source
share