I have a directory of identically structured csv files. I'm trying to load all of them into a single data.frame. Currently I use lapply()
with read.csv()
to get a list of data.frames and I am looking for an elegant way to convert this list to a data.frame that avoids an explicit loop.
The result of my lapply(list.of.file.names,read.csv)
can be approximated as this structure:
list.of.dfs <- list(data.frame(A=sample(seq(from = 1, to = 10), size = 5),
B=sample(seq(from = 1, to = 10), size = 5)),
data.frame(A=sample(seq(from = 1, to = 10), size = 5),
B=sample(seq(from = 1, to = 10), size = 5)),
data.frame(A=sample(seq(from = 1, to = 10), size = 5),
B=sample(seq(from = 1, to = 10), size = 5))
)
What is an elegant version of the following line that works for arbitrary length lists:
one.data.frame <- rbind(list.of.dfs[[1]],list.of.dfs[[2]],list.of.dfs[[3]])
I can do this with a for loop, but is there a vector-based solution?