rbind Function in R (Example)

This page explains how to bind the rows of two data frames with the rbind() function in the R programming language.

Example Data Frames

First data frame:

my_data <- data.frame(x1 = 1:5,             # Create first data frame
                      x2 = letters[1:5])
my_data
# x1 x2
#  1  a
#  2  b
#  3  c
#  4  d
#  5  e

Second data frame:

new_data <- data.frame(x1 = 999,            # Create second data frame
                       x2 = "new")
new_data
#  x1  x2
# 999 new

Apply rbind Function to Data Frames

combined_data <- rbind(my_data, new_data)   # Bind both data frames
combined_data
#  x1  x2
#   1   a
#   2   b
#   3   c
#   4   d
#   5   e
# 999 new

Video Example

The following video shows another example on how to apply the rbind function in R. Furthermore, the video shows how to apply the rbind.fill function of the dplyr package.

YouTube

By loading the video, you agree to YouTube’s privacy policy.
Learn more

Load video

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top