This lesson is called Binding Data Frames, part of the R in 3 Months (Fall 2021) course. This lesson is called Binding Data Frames, part of the R in 3 Months (Fall 2021) course.
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
Solution
Heads up: in the video I forgot to add two lines of code in the video to add the year. Lines 24 and 50 in the code below have the code that is missing in the video.
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
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 dplyrwebsite.
Have any questions? Put them below and we will help you out!
You need to be signed-in to comment on this post. Login.
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
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_")) %>%
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.
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:
https://www.loom.com/share/4dffa13937994d65bb212ecd544e8e20
You need to be signed-in to comment on this post. Login.
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 • 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 • 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 • May 3, 2021
Sorry I don't see bind rows in the solution, did I miss it?
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_")) %>%
JULIO VERA DE LEON • 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 computingnumber_of_students = replace_na(number_of_students, "0")
. Caused by error invec_assign()
: ! Can't convertreplace
to match type ofdata
.So, I just had to remove the quotation marks from the 0, in order to get it work.
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 inna_if()
: ! Can't converty
to match type ofx
. Runrlang::last_trace()
to see where the error occurred. This video (link below) provides a bit more detail: https://www.loom.com/share/4dffa13937994d65bb212ecd544e8e20