R - list element matching (usage of %in% with lists)

21 Jan 2018

Can test the existence of a given vector within a list directly with %in%:

mylist1 <- list(c(1,2,3,4,5), c(5,6,7))
#[[1]]
#[1] 1 2 3 4 5

#[[2]]
#[1] 5 6 7

list(c(5,6,7)) %in% mylist1
#[1] TRUE

list(c(5,6)) %in% mylist1
#[1] FALSE

[ R  data_structure  ]