user3390486
user3390486

Reputation: 159

check elements of a list

I have a list of 1000 lists of booleans which is the result of a duplicated() check on the original lists of numbers. I need to find which of these lists contains a TRUE result and I need to know the position of the list where it appears in the 1000. i.e. I can then type

my.list[[456]]
[1] FALSE FALSE FALSE TRUE FALSE

And then use this to delete the elements from my list where a TRUE appears

Upvotes: 0

Views: 51

Answers (1)

F. Privé
F. Privé

Reputation: 11728

# An example
l <- list(c(TRUE, FALSE), c(FALSE, FALSE), c(FALSE))
# The indices you want
l2 <- lapply(l, which)
# The number of TRUEs for each element of l
l3 <- lengths(l2)
# The initial list, without the elements containing a TRUE
l4 <- l[l3 == 0]

Upvotes: 2

Related Questions