按值过滤列表列表

时间:2018-11-01 22:25:02

标签: r list lapply

我有一个列表列表,例如下面的“输入列表”。我想对所有“ 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

1 个答案:

答案 0 :(得分:3)

您可以尝试:

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)
相关问题