Union of two Objects in R Programming – union() Function
union() function in R Language is used to combine the data of two objects. This function takes two objects like Vectors, dataframes, etc. as arguments and results in a third object with the combination of the data of both the objects.
Syntax: union(x, y)
x and y: Objects with sequence of items
Example 1: Union of two Vectors
 1 2 3 4 5 6 8 9
Here in the above code, the vector x1 contains values from 1-6, and x2 has two values. Now the union of these two vector x1 and x2 will combine each of the values present in them just once.
Note: Union of two vectors removes the duplicate elements in the final vector.
Example 2: Union of two dataframes
[]  5 6 7 []  1 1 1 []  2 3 4 []  2 2 2
Here in the above code, we have created two data frames first with x1, x2 and second have y1, y2. Union of these two data frames creates a third data frame with combined values.