Using lapply and read.csv on multiple files (in R)

csv, lapply, r

Solution

Try just removing the: `i <- paste(".\\",i,sep="")`

read.csv should work fine with the `list.files(full.names=TRUE)` output

setwd("./Data")
filenames <- list.files(full.names=TRUE)  
All <- lapply(filenames,function(i){
  read.csv(i, header=TRUE, skip=4)
})

Problem

I guess this is a bit of a beginner's question but I haven't quite found an answer or figured out what I'm doing wrong. I'm trying to read 20 CSV files that are stored in a separate directory using: ``` setwd("./Data") filenames <- list.files() All <- lapply(filenames,function(i){ i <- paste(".\\",i,sep="") read.csv(i, header=TRUE, skip=4) }) ``` And I get the following error: ``` Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file '.\filename.csv': No such file or directory ``` Where filename stand for the name of the first file in my folder. Thanks in advance!

Original source