问题
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