You can use something like:
ll[which(sapply(ll, `[[`, 1) == .4)]
But you may run into floating point problems ....
Here is MRE:
A list with 4 items.
ll <- list(list(.4, 1), list(.1, 2), list(.3, 3), list(.4, 4)) # [[1]] # [[1]][[1]] # [1] 0.4 # # [[1]][[2]] # [1] 1 # # # [[2]] # [[2]][[1]] # [1] 0.1 # # [[2]][[2]] # [1] 2 # # # [[3]] # [[3]][[1]] # [1] 0.3 # # [[3]][[2]] # [1] 3 # # # [[4]] # [[4]][[1]] # [1] 0.4 # # [[4]][[2]] # [1] 4
Apply the proposed solution:
ll[which(sapply(ll, `[[`, 1) == .4)] # [[1]] # [[1]][[1]] # [1] 0.4 # # [[1]][[2]] # [1] 1 # # # [[2]] # [[2]][[1]] # [1] 0.4 # # [[2]][[2]] # [1] 4
Adding a few conditions is pretty similar:
ll[which(sapply(ll, `[[`, 1) == .4 & sapply(ll, `[[`, 2) == 1)] # [[1]] # [[1]][[1]] # [1] 0.4 # # [[1]][[2]] # [1] 1
A5C1D2H2I1M1N2O1R2T1
source share