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
  • 313
  • 1
  • 10
  • 1
    I guess you meant `data_csv = lapply(myfiles, read.csv, header = FALSE, sep = ";")` – Ronak Shah Jun 04 '20 at 08:44
  • Regarding the last question: Use the `skip` parameter, see `help("read.table")`. But I would read them with the header, e.g., `data_csv <- lapply(myfiles, read.csv, sep = ";")` and then do `data_csv <- do.call(rbind, data_csv)`. – Roland Jun 04 '20 at 08:48
  • Thanks, This generate a list. How can I get dataframe – AsiJapan Jun 04 '20 at 08:49

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
  • 377,200
  • 20
  • 156
  • 213