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

我怕爱的太早我们不能终老 提交于 2019-12-31 05:31:12

问题


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) subset(list,nrow(list$'x')=30))

But it is showing error. Please help!


回答1:


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)


来源:https://stackoverflow.com/questions/58850863/how-to-extract-a-dataframe-which-is-within-a-list-in-r-using-a-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!