如何使用条件提取 r 列表中的数据框? [英] How to extract a dataframe which is within a list in r, using a condition?

查看:32
本文介绍了如何使用条件提取 r 列表中的数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表,其中包含各种维度的数据框.我想提取那些行数大于 30 的数据框我试过了:

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!

推荐答案

假设你的列表名为list_df,我们可以使用Filter

Assuming your list is called list_df, we can use Filter

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

应用

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

<小时>

我们也可以使用 purrr::keep

purrr::keep(list_df, ~nrow(.) == 30)

这篇关于如何使用条件提取 r 列表中的数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆