简体   繁体   中英

how to use several data.frames in “for” loop in R

I have such problem:

There are several dataframes in my global environment, which have same number of columns, same classes of columns and etc. I know, that they are named like df_1 , df_4 , df_123123 , df_3456 and etc

So, i'd like to bind them together using bind_rows() function in "For" loop.

I tried to do this, but got an error

for (i in ls()[grepl("df",ls())]){
    Final_df<- bind_rows(Final_df,i)
}

But in my loop i variable becomes a character string, not dataframe, how can i fix it?

Like mentioned in the comment ?get should help you. You noticed already your "i" variable becomes a string variable. So you would have the get the values of a variable based on the variables name.

Example:

a=1
get("a")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM