Row bind data frames with Rbind function in R

Rbind function in R row binds the data frames. In other words, Rbind in R appends or combines vector, matrix or data frame by rows. lets see an example of row bind in R

row bind in R - R bind Example

Note: Column names and the number of columns of the two dataframes needs to be same.

 

Syntax for Rbind function in R:

rbind(x1,x2)

x1,x2 can be data frame, matrix or vector.

Example of Rbind function in R: 

Lets see how to implement Rbind function in R with an example. First lets create two data frames

#Create two data frames

df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Oven", 3), rep("Television", 3)))
df2 = data.frame(CustomerId = c(4:7), Product = c(rep("Television", 2), rep("Air conditioner", 2)))
  df1 will be 

CustomerId    Product

1          1       Oven

2          2       Oven

3          3       Oven

4          4   Television

5          5   Television

6          6   Television

 

  df2 will be 

CustomerId      Product

1          4      Television

2          5      Television

3          6  Air conditioner

4          7  Air conditioner

Now, Row bind (rbind) these two data frames as shown below

# row bind the data frames with rbind function in R.

rbinded_df<-rbind(df1,df2)
rbinded_df

so the resultant rbind data frame will be

  CustomerId    Product

1           1            Oven

2           2            Oven

3           3            Oven

4           4        Television

5           5        Television

6           6        Television

7           4        Television

8           5        Television

9           6    Air conditioner

10          7    Air conditioner

rbind function in r                                                                                                                rbind in R