Skip to Content
Learn
Joining Tables in R
Concatenate Data Frames

Sometimes, a dataset is broken into multiple tables. For instance, data is often split into multiple CSV files so that each download is smaller.

When we need to reconstruct a single data frame from multiple smaller data frames, we can use the dplyr bind_rows() method. This method only works if all of the columns are the same in all of the data frames.

For instance, suppose that we have two data frames:

df1
nameemail
Katja Obingerk.obinger@gmail.com
Alison HendrixalisonH@yahoo.com
Cosima Niehauscosi.niehaus@gmail.com
Rachel Duncanrachelduncan@hotmail.com
df2
nameemail
Jean Grayjgray@netscape.net
Scott Summersssummers@gmail.com
Kitty Prydekitkat@gmail.com
Charles Xaviercxavier@hotmail.com

If we want to combine these two data frames, we can use the following command:

concatenated_dfs <- df1 %>% bind_rows(df_2)

That would result in the following data frame:

nameemail
Katja Obingerk.obinger@gmail.com
Alison HendrixalisonH@yahoo.com
Cosima Niehauscosi.niehaus@gmail.com
Rachel Duncanrachelduncan@hotmail.com
Jean Grayjgray@netscape.net
Scott Summersssummers@gmail.com
Kitty Prydekitkat@gmail.com
Charles Xaviercxavier@hotmail.com

Instructions

1.

An ice cream parlor and a bakery have decided to merge.

The bakery’s menu is stored in the data frame bakery, and the ice cream parlor’s menu is stored in the data frame ice_cream.

Create their new menu by concatenating the two data frames into a data frame called menu.

Folder Icon

Take this course for free

Already have an account?