0

I am loading a bunch of csv files simultaneously from a local directory using the following code:

myfiles = do.call(rbind, lapply(files, function(x) read.table(x, stringsAsFactors = FALSE, header = F, fill = T, sep=",", quote=NULL)))

and getting an error message:

Error in rbind(deparse.level, ...) : 
  numbers of columns of arguments do not match

I am afraid that quotes cause this as I inspect the number of columns in each of the 4 files I see that file number 3 contain 10 columns (incorrect) and the rest only 9 columns (correct). Looking into the corrupted file - it is definitely caused by quotes that cause a column split.

Any help apreciated

Nir Regev
  • 135
  • 1
  • 2
  • 7
  • try it without the buggy csv and if it works then just resolve that csv's issue somehow. That error message is because the number of columns don't match. So maybe bring it into R alone and then merge the columns and resave. – zacdav Mar 29 '16 at 13:01
  • What do you mean by buggy csv, I am using read.table ? – Nir Regev Mar 29 '16 at 13:05

1 Answers1

0

Found the answer, quote parameter should be set to quote ="\""

myfiles = do.call(rbind, lapply(files, function(x) read.table(x, stringsAsFactors = FALSE, header = F, fill = T, sep=",", quote ="\"")))
Nir Regev
  • 135
  • 1
  • 2
  • 7