0

Why I get the error "Error in read.table(file = file, header = header, sep = sep, quote = quote, : argument "file" is missing, with no default" when I run this code:

mydir = "E:/Data"
myfiles = list.files(path=mydir, pattern="*.csv", full.names=TRUE)
data_csv = ldply(myfiles, read.csv(header = FALSE, sep = ";")

Furthermore as all of them as the same header How can I only read it once?

AsiJapan
  • 311
  • 1
  • 10

1 Answers1

3

You can use :

data_csv <- do.call(rbind, lapply(myfiles, read.csv, sep = ";"))

Or with purrr's map_df

data_csv <- purrr::map_df(myfiles, read.csv, sep = ";"))

If there are lot of files you can use data.table functions.

library(data.table)
data_csv <- rbindlist(lapply(myfiles, fread))
Ronak Shah
  • 355,584
  • 18
  • 123
  • 178