Skip to content

Is there a convenient function that can check if a vector is a subset of another one?

2 messages · Terry Mu, Pierre Kleiber

#
x <- 2:5
y <- 1:10

Is there something like:

is.subset(x, y) == T

Thank you,
#
all(x %in% y) should do what you want:

 > x <- 2:5
 > y <- 1:10
 > all(x %in% y)
[1] TRUE
 > all(y %in% x)
[1] FALSE
 >

Cheers, Pierre
Terry Mu wrote: