Try this:
obj.names <- paste0("file.", seq_along(filenames))
dt <- rbind.fill(mget(Filter(exists, obj.names)))
Question
I have many data frames which are usually in the format file.[i]
, but occasionally there are missing data frames:
file.1 file.2 file.3 file.4 file.5 file.6 file.7 file.9 file.11 file.13
What I tried to do is this:
dt <- do.call(rbind.fill,
lapply(paste("file.", 1:length(filenames), sep=""), get))
And I get:
Error in FUN(c("file.1", "file.2", "file.3", "file.4", "file.5", "file.6", :
object 'file.8' not found
Is there a way to make rbind.fill
ignore the missing data frames?
Solution
Try this:
obj.names <- paste0("file.", seq_along(filenames))
dt <- rbind.fill(mget(Filter(exists, obj.names)))