R - loop through multiple dataframes from a list of names

后端 未结 2 1523
一个人的身影
一个人的身影 2021-01-16 09:08

I have a number of large DFs and I want to loop through them. Instead of binding them together to make a big list I thought I should make a simple vector with their names an

相关标签:
2条回答
  • 2021-01-16 09:40

    In your own code, just replace print(nrow(i)) with print(nrow(get(i))), since i is: chr "DF1" etc.

    for (i in MyDFs) {
         print(nrow(get(i)))
    }
    [1] 3
    [1] 3
    [1] 3
    
    0 讨论(0)
  • 2021-01-16 09:49

    Or

     sapply(mget(MyDFs),nrow)
     #DF1 DF2 DF3 
     # 3   3   3 
    

    If you don't want to create a vector MyDFs

     sapply(mget(ls(pattern="DF")), nrow) #should also work
    
    0 讨论(0)
提交回复
热议问题