Reputation: 2306
Is it possible to locate NAs (missing values) and return their location with both list and column?
Please consider this data:
list1 <- list(a = c(1, 2), b = c(3, 4), c = c(5, NA))
list2 <- list(d = c(6, 7), e = c(8, 9), f = c("a", "b"))
mylist <- mget(c("list1", "list2"))
The expected return would be something like list1$c
.
I tried to use rlist
with the function list.search
. Thank you in advance for your help.
Upvotes: 0
Views: 665
Reputation: 440
A pretty straightforward approach would be using rapply
with is.na()
. Something like this would be close to your desired result:
> rapply(mylist, is.na)
a1 a2 b1 b2 c1 c2 d1 d2 e1 e2 f1 f2
FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
> which(rapply(mylist, is.na))
c2
6
Upvotes: 1