Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R check if list of lists contains specific list

Tags:

list

r

There are three lists:

a = list(1,2)
b = list(2,3)
c = list(a,b)

The command a %in% c yields FALSE FALSE. The result I would like to see is TRUE since a is an element of list c. How do I achieve this?

like image 232
volfi Avatar asked Dec 06 '25 13:12

volfi


1 Answers

Check whether each component is identical to a and return TRUE if any of those comparisons are TRUE.

any(sapply(c, identical, a))
## [1] TRUE
like image 158
G. Grothendieck Avatar answered Dec 08 '25 07:12

G. Grothendieck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!