Skip to content
R for the Rest of Us Logo

Binding Data Frames

This lesson is locked

Get access to all lessons in this course.

If the video is not playing correctly, you can watch it in a new window


Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Your Turn

  1. Import 2017-2018 enrollment data into a data frame called enrollment_by_race_ethnicity_17_18 and clean it using the code you used for the 2018-2019 data

  2. Use bind_rows() to make a enrollment_by_race_ethnicity data frame.

Hint: You’ll need to change some of your code from importing the 2018-2019 data to make the race_ethnicity variable get recoded correctly!

Learn More

The best place to learn about binding data is the dplyr website.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Isaac Macha

Isaac Macha

April 22, 2021

when putting a new column, I keep getting this error. How do I solve this :

Error in FUN(left) : invalid argument to unary operator

See below code enrollment_by_ethnicity_18_19 %>% mutate(year = 2018)

tawheeda wahabzada

tawheeda wahabzada

April 28, 2021

Hi David, in the solutions, you noted that lines 25 and 51 have the missing code. I only see blank spaces.

Atlang Mompe

Atlang Mompe

May 2, 2021

Hi David, did you intentionally omit the binding code? In any case I figured it out, but just want to flag that it is not in the solutions. Thanks, Atty

Christine Vandenberghe

Christine Vandenberghe

May 3, 2021

Sorry I don't see bind rows in the solution, did I miss it?

Maria Cristina Limlingan

Maria Cristina Limlingan

November 15, 2021

HI David,

I'm still getting NAs for race_ethnicity even if I changed the code to this - not sure what else to try? mutate(race_ethnicity = str_remove(race_ethnicity, "x2017_2018_")) %>%



April 30, 2022

Hi, I ran into a similar issue when we were using the replace_na with "0", in this case for the second dataset (17-18) I received this from the console:

Error in mutate(): ! Problem while computing number_of_students = replace_na(number_of_students, "0"). Caused by error in vec_assign(): ! Can't convert replace to match type of data .

So, I just had to remove the quotation marks from the 0, in order to get it work.

Andrew Paquin

Andrew Paquin

April 24, 2023

Hi Dave and Charlie, I've run into a problem. I duplicated my code for the 2018-19 data and adapted it for the 2017-18 data. When I run it, however, I get an error message pertaining to line 73 - mutate(number_of_students = na_if(number_of_students, "-")). What puzzles me is that the exact same line works as expected in the original code chunk. Here's the error message: Error in mutate(): ℹ In argument: number_of_students = na_if(number_of_students, "-"). Caused by error in na_if(): ! Can't convert y to match type of x . Run rlang::last_trace() to see where the error occurred. This video (link below) provides a bit more detail: