To check if a set contains all the items of another set in R, you can use the setequal
function.
In this example,
setA
and setB
containing some elements.setequal
function to compare the equality of the two sets.setequal
function returns a boolean value: TRUE
if all elements of setB
are also present in setA
, and FALSE
otherwise.setA
is a subset of setB
.setA <- c(1, 2, 3, 4, 5)
setB <- c(2, 3)
isSubset <- setequal(setA, setB)
print(paste('Is setA a subset of setB?', isSubset))
Is setA a subset of setB? FALSE
In this example,
setA
and setB
containing some elements.setequal
function to compare the equality of the two sets.setequal
function returns a boolean value: TRUE
if all elements of setA
are also present in setB
, and FALSE
otherwise.setA
is a superset of setB
.setA <- c(1, 2, 3, 4, 5)
setB <- c(2, 3)
isSuperset <- setequal(setB, setA)
print(paste('Is setA a superset of setB?', isSuperset))
Is setA a superset of setB? FALSE
In this tutorial, we learned How to check if a Set contains all the items of Another Set in R language with well detailed examples.