Get access to all lessons in this course.
-
Advanced Data Wrangling and Analysis
- Overview
- Importing Data
- Tidy Data
- Reshaping Data
- Dealing with Missing Data
- Changing Variable Types
- Advanced Variable Creation
- Advanced Summarizing
- Binding Data Frames
- Functions
- Merging Data
- Renaming Variables
- Quick Interlude to Reorganize our Code
- Exporting Data
-
Advanced Data Visualization
- Data Visualization Best Practices
- Tidy Data
- Pipe Data Into ggplot
- Reorder Plots to Highlight Findings
- Line Charts
- Use Color to Highlight Findings
- Declutter
- Use the scales Package for Nicely Formatted Values
- Use Direct Labeling
- Use Axis Text Wisely
- Use Titles to Highlight Findings
- Use Color in Titles to Highlight Findings
- Use Annotations to Explain
- Tweak Spacing
- Customize Your Theme
- Customize Your Fonts
- Try New Plot Types
-
Advanced RMarkdown
- Advanced Markdown Text Formatting
- Tables
- Advanced YAML
- Inline R Code
- Making Your Reports Shine: Word Edition
- Making Your Reports Shine: HTML Edition
- Making Your Reports Shine: PDF Edition
- Presentations
- Dashboards
- Other Formats
-
Wrapping Up
- You Did It!
Going Deeper with R
Binding Data Frames
This lesson is locked
This lesson is called Binding Data Frames, part of the Going Deeper with R course. This lesson is called Binding Data Frames, part of the Going Deeper with R course.
Transcript
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
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 dataUse 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.
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)
David Keyes
April 22, 2021
That's odd. Can you post your full code so I can see what's going on?
Isaac Macha
April 22, 2021
I found the solution, the same problem as before, not piping to an object before mutating.
tawheeda wahabzada
April 27, 2021
Hi David, in the solutions, you noted that lines 25 and 51 have the missing code. I only see blank spaces.
David Keyes
April 28, 2021
Oops, typo! I've updated it to be lines 24 and 50.
Atlang Mompe
May 1, 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
David Keyes
May 3, 2021
Sorry about that! Updated now.
Atlang Mompe
May 3, 2021
Great, thank you David, I have the same code as well.
Christine Vandenberghe
May 3, 2021
Sorry I don't see bind rows in the solution, did I miss it?
Christine Vandenberghe
May 3, 2021
Sorry disregard, just saw your previous note :)
Maria Cristina Limlingan
November 14, 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_")) %>%
David Keyes
November 14, 2021
Can you post your full code as a GitHub gist and share the link please?
David Keyes
November 15, 2021
Try changing the x2017_2018 to x2017_18. I think that's your issue.
Maria Cristina Limlingan
November 17, 2021
It worked! I'm both glad and (a little) embarrased that it was a simple issue. Appreciate your help! :)
David Keyes
November 17, 2021
This type of thing is VERY common! Most of my bugs are from small things like this.
JULIO VERA DE LEON
April 29, 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.
Charlie Hadley
May 3, 2022
Hello Julio,
Thanks for reporting this! It's due to a change in how replace_na() works, it is no longer allowed to "change data types" which means we need to use 0 if the column is numeric and "0" if the column is a character column.
In case you're interested, you can see the documentation for this change in the NEWS.md file for the package. But please note the language used here is quite technical.
Thanks,
Charlie
Andrew Paquin
April 23, 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/4dffa13937994d65bb212ecd544e8e20Andrew Paquin
April 23, 2023
I should also note that David had that line in his code, and it worked in the videos. That being said, I went to the original files and I noticed two things:
I just deleted the three mutate lines pertaining to the whole na situation, and now it works. I'm still confused why it worked in David's video.
David Keyes
April 24, 2023
It's a bit complicated, but I'll explain the issue in our live session on Wednesday.