To find the union of two sets in R, you can use the union function.
In this example,
set1
and set2
, containing some elements.set1
and set2
to obtain their union.set1 <- c(1, 2, 3)
set2 <- c(3, 4, 5)
unionSet <- union(set1, set2)
print("Union of set1 and set2:")
print(unionSet)
Union of set1 and set2: [1] 1 2 3 4 5
In this example,
set1
and set2
, containing some string elements.set1
and set2
to obtain their union.set1 <- c('apple', 'banana', 'orange')
set2 <- c('orange', 'pear', 'grape')
unionSet <- union(set1, set2)
print("Union of set1 and set2:")
print(unionSet)
Union of set1 and set2: [1] "apple" "banana" "orange" "pear" "grape"
In this tutorial, we learned How to find Union of Two Sets in R language with well detailed examples.