0

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.

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)
2
  • Do either of all_df <- do.call(rbind, all_df) or all_df <- lapply(all_df, rbind) work with your data? Commented Jul 11, 2022 at 1:26
  • No, do.call creates a df with one column and the names of the dfs, the other crashes. "object 'df_list' of mode 'function' was not found" Commented Jul 11, 2022 at 1:37

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.