I have a number of files progressively named from 1 to 22, i.e. "chr1.csv", "chr2.csv" ... "chr22.csv". Each file contains a database with the same variables as columns. I would like to create a loop so as to read these files and save them as elements of a list.
I have tried this snippet of code but it is not working.
file <- vector("character", 22)
data<-vector("list", length = 22)
for (i in 1:22) {
str <- gsub("number", i, "chrnumber.csv")
file[i] <- str
}
for (i in file) {
data <- read.csv(i, sep="")
}