Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R rbind multiple dataframes with names stored in a vector/list

I have a list that references the names of multiple dataframes

df_list

[[1]]
[1] "df_1"

[[2]]
[1] "df_2"

....

[[10]]
[10] "df_10"

How can I run the rbind command referencing df_list so I don’t have to reference every one of the 10 names.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

all_df <- rbind(df_list)

Instead of

all_df <- rbind(df_1,df_2,df_3,df_4,df_5,df_6,df_7,df_8,df_9,df_10)

>Solution :

Something like this may work.

Example data: a list with the name of the iris data frame, twice.

df_list<- list("iris", "iris")
df_list

[[1]]
[1] "iris"

[[2]]
[1] "iris"

Then use as.name to convert the strings to the variable names:

all_df <- do.call(rbind, lapply(df_list, as.name))
nrow(df)

[1] 300
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading