我有一个嵌套列表,have_list
.中间是一个包含四个整数向量的列表,a
、b
、c
、d
.
对于a
、b
、c
、d
,每个都有一个唯一的cutoff
值.我想找出整数大于相关截止值时的第一个位置.
如果a-d有相同的cutoff
,我可以这样做:
rapply(have_list, function(x) which.max(x > cutoff), how = "list")
My specific question是如何使用a-d的各个截止值,如果可能的话,不需要for
个循环.我似乎在网上找不到任何东西,不过如果我忽略了前面的问题,我深表歉意.
Sample data
cutoff <- c(a = 5, b = 17, c = 11, d = 7)
set.seed(05062020)
have_list <- list(Outer1 = list(a = sample(1:25, 10),
b = sample(1:25, 10),
c = sample(1:25, 10),
d = sample(1:25, 10)),
Outer2 = list(a = sample(1:25, 10),
b = sample(1:25, 10),
c = sample(1:25, 10),
d = sample(1:25, 10)))
Desired data
want_list <- list(Outer1 = list(a = 2, b = 2, c = 1, d = 1),
Outer2 = list(a = 1, b = 4, c = 4, d = 1))