Question

I have several data frames stored in R memory among several other objects. Their particularity is that they are all named as "Station_Year.df". I want to merge all these data frames into one.

I tried:

df_list <- ls(pattern=".df")
dataset <- rbind(df_list)

But I get a data frame with the names of the data frames...

Was it helpful?

Solution

You should use mget to get the data of each dataframe of the df_list. So you can do:

dataset <- do.call(rbind, mget(df_list))

Note that this implies that all the rows are of the same length. Probably you find useful also the merge function. Thanks alexis_laz, I forgot the do.call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top