我有一个列表列表,如下面的“输入列表”。我想过滤所有“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)
关于r - 按值过滤列表的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53110224/