0

enter image description hereI am reshaping my question,

I need to import several CSV files of 296x2 (296 rows x 2 columns) into a single dataset.

First column is the same for all files.

I would like to merge all the CSV into a single dataset columnwise (conserving only the first column as row name once. In other words, All the 329 CSV files are comma delimited and are all the same 296x2. I would like to end up with a 296x329 dataset that includes the second column of each dataset.

Thanks in advance Emiliano

MFR
  • 2,049
  • 3
  • 29
  • 53
Emiliano
  • 47
  • 9
  • 1
    How have you 'merged' the data in the first place? Perhaps you should be using `cbind` to put your data together? – SymbolixAU Sep 11 '16 at 23:34
  • Yeah probably I should! I will write down in the post how did I do, Thanks – Emiliano Sep 11 '16 at 23:43
  • Without seeing your data or the code you've written it's hard to help you. Have a read of [how to make a reproducible example](http://stackoverflow.com/q/5963269/5977215) - you're more likely to get assistance if other people can see what you've done. – SymbolixAU Sep 11 '16 at 23:44

1 Answers1

1

Without knowing your data it's difficult to say, but assume you have your dataset in a folder name: C:/foo/. Try this one:

filenames <- list.files('C:/foo/', pattern="*.csv", full.names=TRUE)
la <- lapply(filenames, read.csv)


Reduce(function(x, y) merge(x, y, by="Wavelength"), la)
MFR
  • 2,049
  • 3
  • 29
  • 53
  • Thanks eddie, you lines managed to import everything together only in single huge column tough :( all the 329 CSV files are comma delimited and are all the same 296x2. I would like to end up with a 296x329 dataset that includes the second column of each dataset :) – Emiliano Sep 12 '16 at 01:15
  • oh, are the first column is same for all the files? – MFR Sep 12 '16 at 01:30
  • Try this one and let me know please? dataset <- do.call("merge",append(lapply(file_list, read.csv, header = TRUE), by= c("First coloumn name" ) – MFR Sep 12 '16 at 01:39
  • Hello Eddie, yes the first column is the same for all. I am failing to compile the lines , Error: unexpected symbol in: "dataset <- do.call("merge",append(lapply(file_list, read.csv, header = TRUE, by= c("Wavelength" ) dataset" – Emiliano Sep 12 '16 at 02:20
  • I think I found the solution, I edited the answer, Please try this one and let me know. – MFR Sep 12 '16 at 02:28
  • Thanks eddie, I am still having issues, dont get why, when i run the reduce operation, I get: Error: cannot allocate vector of size 1024.0 Mb In addition: There were 32 warnings (use warnings() to see them) – Emiliano Sep 12 '16 at 03:38
  • I have attached the header of one of my excel files in case it could result useful – Emiliano Sep 12 '16 at 03:40
  • I tried in a small dataset and it worked. There are some tricks to manage memory in R http://stackoverflow.com/questions/1358003/tricks-to-manage-the-available-memory-in-an-r-session?rq=1 – MFR Sep 12 '16 at 03:40