Reputation: 107
I have around 100 dataframes with same structure, like d1
, d2
,d3
, ..., d10
, d11
, ..., d100
. I have to rbind
them together, like rbind(d1,d2,.....dxx)
.
I don't want to manually write all dataframes names because in that case I have manually write more than 100 dataframe names and that number could increase in future. can you please help write an automatic way to rbind(d1,d2,d3,...,d10, d11,.....,d100,....)
?
Upvotes: 4
Views: 318
Reputation: 1
Example - from my work:
filename_vector <- paste0(i, sep="_", df$unique.label.within.df,
sep="", "intended.filename.csv")
Upvotes: -1
Reputation: 397
Building on akrun's elegant answer (using mget()
), but using dplyr
's efficient bind
implementation to avoid the do.call()
:
library(dplyr)
mget(paste0("d",1:100)) %>% bind_rows()
Upvotes: 0
Reputation: 886948
We can use mget
to return a list
of values
out <- do.call(rbind, mget(paste0("d", 1:100)))
Upvotes: 2
Reputation: 1236
First create a character vector of all objects that you want to bind, like:
NameDf <- paste("d", 1:100, sep = "")
Now, first call each object using get
function and bind them together using do.call
NewDf <- do.call(cbind, lapply(NamesDf, FUN = function(x) get(x)))
Upvotes: 2