I have a list of lists like this:
How can I find every number from 1-100 that is not in the list(cluster)?
I have a list of lists like this:
How can I find every number from 1-100 that is not in the list(cluster)?
I believe something like
cluster <- list(c(30,37,21), c(10,19,20), c(22, 10, 11))
setdiff(1:100, unlist(cluster))
should work. unlist()
collapses the list into a single vector of integers; setdiff(x,y)
finds all the values in x
that are not contained in y
.
Slightly less efficiently, but more generally
v <- 1:100
u <- unlist(cluster)
v[!v %in% u]
If 1:100
is the complete space for values in the cluster, maybe you can try
(1:100)[-unlist(cluster)]
since the values in the cluster can play as indices as well in your case here.