How to extract a dataframe which is within a list in r, using a condition?

后端 未结 1 1022
梦如初夏
梦如初夏 2021-01-28 13:09

I have a list which has dataframes of various dimensions. I want to extract those dataframes who rows greater than 30 I tried :

DR<-sapply(list, function(x)         


        
相关标签:
1条回答
  • 2021-01-28 13:19

    Assuming your list is called list_df, we can use Filter

    Filter(function(x) nrow(x) == 30, list_df)
    

    Or sapply

    list_df[sapply(list_df, nrow) == 30]
    

    We can also use purrr::keep

    purrr::keep(list_df, ~nrow(.) == 30)
    
    0 讨论(0)
提交回复
热议问题