I\'m using R-Studio 0.99.491 and R version 3.2.3 (2015-12-10). I\'m a relative newbie to R, and I\'d appreciate some help. I\'m doing a project where I\'m trying to use the
You can use map_df
from purrr
package instead of lapply
, to directly have all results combined as a data frame.
map_df(files, read.table, skip = 3, header = TRUE, stringsAsFactors = FALSE)
Another option is fread
from data.table
library(data.table)
rbindlist(lapply(files, fread, skip=3))
do.call()
is your friend.
big.list.of.data.frames <- lapply(files, function(x){
read.table(x, skip = 3, header = TRUE, stringsAsFactors = FALSE)
})
or more concisely (but less-tinkerable):
big.list.of.data.frames <- lapply(files, read.table,
skip = 3,header = TRUE,
stringsAsFactors = FALSE)
Then:
big.data.frame <- do.call(rbind,big.list.of.data.frames)
This is a recommended way to do things because "growing" a data frame dynamically in R is painful. Slow and memory-expensive, because a new frame gets built at each iteration.