Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

finding position number of an object within a list

Tags:

list

r

tidyverse

I have a list as follows:

list(c(TRUE, FALSE), TRUE, FALSE)

The list contains only one object with TRUE, all others are a mix of TRUE and FALSE. I want to work out the position number of the TRUE only object, in this case the answer is 2.

It sounds simple but I've failed so far.

Any ideas to solve this?

like image 436
cephalopod Avatar asked Dec 22 '22 21:12

cephalopod


1 Answers

Use Position like this:

L <- list(c(TRUE, FALSE), TRUE, FALSE) # test data
Position(isTRUE, L)
## [1] 2
like image 194
G. Grothendieck Avatar answered Jan 05 '23 02:01

G. Grothendieck