r - 按值过滤列表列表
问题描述
我有一个列表列表,例如下面的“输入列表”。我想为所有“cor”> 0.2 过滤它,如下面的输出列表。像这样的嵌套列表对我来说很棘手,因此非常感谢任何提示。
输入列表
$TimeForOrder
cor lag
4893 0.09260373 1610
$OrderForPick
cor lag
3263 0.2926644 -20
$TimeForShip
cor lag
2925 0.1249888 -358
$TimeForRelease
cor lag
3285 0.2335587 2
输出列表
$OrderForPick
cor lag
3263 0.2926644 -20
$TimeForRelease
cor lag
3285 0.2335587 2
解决方案
你可以试试:
Filter(function(x) x$cor >= 0.2, ll)
#$OrderForPick
# cor lag
#1 0.292 -2
#
#$TimeForRelease
# cor lag
#1 0.233 2
还有可能:
ll[vapply(ll, function(x) x$cor >= 0.2, logical(1))]
数据:
TimeForOrder <- data.frame(cor = 0.092, lag = 1610)
OrderForPick <- data.frame(cor = 0.292, lag = -2)
TimeForShip <- data.frame(cor = 0.124, lag = -358)
TimeForRelease <- data.frame(cor = 0.233, lag = 2)
ll <- list(TimeForOrder = TimeForOrder, OrderForPick = OrderForPick, TimeForShip = TimeForShip, TimeForRelease= TimeForRelease)
推荐阅读
- android - 添加数据不会出现在 Firebase Realtime 中
- c++ - C++ 为 void 指针分配一个字符串
- django - 我如何将数字和字符串添加到我的 django
- python - 永久更改字符串的 Python 函数
- r - 从虚拟变量中创建因子并计数
- python - 你如何将数据框转换为二维 numpy 数组
- php - OneSignal:仅向一位用户发送推送通知
- java - 如何用 Spring 或 POJO 类替换 org.jboss.resteasy.core.ResourceMethodInvoker
- python - 随着阶数的增加,巴特沃斯滤波器看起来很奇怪
- haskell - 什么是“你调用的函数”,什么是“调用你的函数”?