Binding rows and columns of a Data Frame in R – bind_rows() and bind_cols() Function Last Updated : 26 May, 2020 Improve Improve Like Article Like Save Share Report bind_rows() function in R Programming is used to combine rows of two data frames. Syntax: bind_rows(data1, data2, id) Parameter: id: dataframe identifier data1, data2: data frame to combine Example: Combining Rows # R program to illustrate # combine rows # Install dplyr package install.packages("dplyr") # Load dplyr package library("dplyr") # Create three data frames data1 <- data.frame(x1 = 1:5, x2 = letters[1:5]) data2 <- data.frame(x1 = 0, x3 = 5:9) data3 <- data.frame(x3 = 5:9, x4 = letters[5:9]) # Apply bind_rows function bind_rows(data1, data2, id = NULL) Output: x1 x2 x3 1 1 a NA 2 2 b NA 3 3 c NA 4 4 d NA 5 5 e NA 6 0 5 7 0 6 8 0 7 9 0 8 10 0 9 Here in the above code, we created 3 data frames data1, data2, data3 with rows and columns in it and then we use bind_rows() function to combine the rows that were present in the data frame. Also where the variable name is not listed bind_rows() inserted NA value. bind_cols() bind_cols() function is used to combine columns of two data frames. Syntax: bind_cols(data1, data2, id) Parameter: id: dataframe identifier data1, data2: data frame to combine Example: Combining Columns # R program to illustrate # combine rows # Install dplyr package install.packages("dplyr") # Load dplyr package library("dplyr") # Create three data frames data1 <- data.frame(x1 = 1:5, x2 = letters[1:5]) data2 <- data.frame(x1 = 0, x3 = 5:9) data3 <- data.frame(x3 = 5:9, x4 = letters[5:9]) # Apply bind_cols function bind_cols(data1, data3, id = NULL) Output: x1 x2 x3 x4 1 1 a 5 e 2 2 b 6 f 3 3 c 7 g 4 4 d 8 h 5 5 e 9 i Here in the above code we have created 3 data frames and then combine their columns by using bind_cols() function. Here we have combined the var. x1, x2 of data1 and x3, x4 of data2 with each other. Like Article Suggest improvement Previous Poisson Regression in R Programming Next Accessing variables of a data frame in R Programming - attach() and detach() function Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Convert an Object to Data Frame in R Programming - as.data.frame() Function Check if the Object is a Data Frame in R Programming - is.data.frame() Function Difference Between as.data.frame() and data.frame() in R Choose Specific Columns of a Data Frame in R Programming - select() Function Rename Columns of a Data Frame in R Programming - rename() Function Convert two columns of a data frame to a named vector in R Calculate Percentiles For Data Frame Columns Using R Convert a Data Frame into a Numeric Matrix in R Programming - data.matrix() Function Modify Data of a Data Frame with an Expression in R Programming - with() Function data.table vs data.frame in R Programming Like akhilsharma870 Follow Article Tags : Programming Language R Language