| is_subset | R Documentation |
Check if all elements of x are also contained in y. This is equivalent
to testing whether setdiff(x, y) is empty.
is_subset(x, y)
x |
The first vector. |
y |
The second vector. |
If x is empty, the result is always TRUE (the empty set is a subset of
any set).
If y is empty and x is not, the result is FALSE.
Duplicates in x are ignored; only set membership is tested.
NA values are treated as ordinary elements. In particular, NA in x
is considered a subset element only if NA is also present in y.
A logical scalar. Returns TRUE if x is a subset of y, i.e. all
elements of x are also elements of y. Returns FALSE otherwise.
Michal Burda
generics::setdiff(), generics::intersect(), generics::union()
is_subset(1:3, 1:5) # TRUE
is_subset(c(2, 5), 1:4) # FALSE
is_subset(numeric(0), 1:5) # TRUE
is_subset(1:3, numeric(0)) # FALSE
is_subset(c(1, NA), c(1, 2, NA)) # TRUE
is_subset(c(NA), 1:5) # FALSE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.