Union of two Objects in R Programming - union() Function Last Updated : 15 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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) Parameters: x and y: Objects with sequence of items Example 1: Union of two Vectors Python3 1== # R program to illustrate # union of two vectors # Vector 1 x1 <- c(1, 2, 3, 4, 5, 6, 5, 5) # Vector 2 x2 <- c(8, 9) # Union of two vectors x3 <- union(x1, x2) print(x3) Output: [1] 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 Python3 1== # R program to illustrate # the union of two data frames # Data frame 1 data_x <- data.frame(x1 = c(5, 6, 7), x2 = c(1, 1, 1)) # Data frame 2 data_y <- data.frame(y1 = c(2, 3, 4), y2 = c(2, 2, 2)) # R union two data frames data_z <- union(data_x, data_y) print(data_z) Output: [[1]] [1] 5 6 7 [[2]] [1] 1 1 1 [[3]] [1] 2 3 4 [[4]] [1] 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. Comment More infoAdvertise with us Next Article Check if Two Objects are Equal in R Programming - setequal() Function A akhilsharma870 Follow Improve Article Tags : Programming Language R Language R-dataStructures R Functions Similar Reads Check if Two Objects are Equal in R Programming - setequal() Function setequal() function in R Language is used to check if two objects are equal. This function takes two objects like Vectors, dataframes, etc. as arguments and results in TRUE or FALSE, if the Objects are equal or not. Syntax: setequal(x, y) Parameters: x and y: Objects with sequence of items Example 1 1 min read Convert values of an Object to Logical Vector in R Programming - as.logical() Function as.logical() function in R Language is used to convert an object to a logical vector. Syntax: as.logical(x)Parameters:Â x: Numeric or character object R - as.logical() Function ExampleExample 1: Basic example of as.logical() Function in R Programming Language.R # R Program to convert # an object to l 1 min read Concatenating Objects in R Programming - combine() Function In R programming, coercion function c() and combine() function are similar to each other but are different in a way. combine() functions acts like c() and unlist() functions but uses consistent dplyr coercion rules. Moreover, combine() function is used to combine factors in R programming. In this ar 2 min read Union() & union_all() functions in Dplyr package in R In this article, we will discuss union() and union_all() functions using Dplyr package in the R programming language. Dataframes in use: Example: R program to create data frames with college student data and display them R # create dataframe1 with college # 1 data data1=data.frame(id=c(1,2,3,4,5), n 2 min read Get Exclusive Elements between Two Objects in R Programming - setdiff() Function setdiff() function in R Programming Language is used to find the elements which are in the first Object but not in the second Object. Syntax: setdiff(x, y) Parameters:Â x and y: Objects with sequence of itemsR - setdiff() Function ExampleExample 1: Apply setdiff to Numeric Vectors in R LanguageR # R 2 min read Convert an Object to Data Frame in R Programming - as.data.frame() Function as.data.frame() function in R Programming Language is used to convert an object to data frame. These objects can be Vectors, Lists, Matrices, and Factors. Syntax: as.data.frame(object) Parameters:Â object: Vector, Matrix, factor, or data frameR - as.data.frame() Function ExampleExample 1: Basic exam 2 min read Like