How to determine that a vector is a subset of a specific vector?

I have two vectors (sets) like this:

first<-c(1,2,3,4,5)
second<-c(2,4,5)

how can i determine if a secondsubset firstor not? is there a function for this?

+4
source share
2 answers

Here is one way

> all(second %in% first)
[1] TRUE
+9
source

Here is another

setequal(intersect(first, second), second)
## [1] TRUE

or

all(is.element(second, first))
## [1] TRUE
+6
source

All Articles