I have a nested list, have_list. At the center is a list with four vectors of integers, a, b, c, d.
For a, b, c, d, each has a unique cutoff value. I would like to find the first positions when the integer is greater than the relevant cutoff value.
I can do this if a-d had the same cutoff by:
rapply(have_list, function(x) which.max(x > cutoff), how = "list")
My specific question is how to use the respective cutoff values for a-d, without for loops, if possible. I can't seem to find anything on the internet or SO, though apologies if I overlooked a previous question.
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))