Using dplyr's join functions in R to filter and merge data frames (CC164)
Ғылым және технология
The ability to use dplyr's join functions to merge and filter data frames in R has made life so much easier than trying to do the same thing with base R. In this Code Club, Pat will demonstrate how to use and the difference between full_join, inner_join, left_join, right_join, and anti_join. He'll demonstrate how to use these functions with a massive data frame that we downloaded from Our World in Data that describes COVID-19 vaccination rates by country and day.
In this episode, Pat uses #inner_join, #left_join, #right_join, #full_join, and #anti_join from the #dplyr #R package in #Rstudio. The accompanying blog post can be found at www.riffomonas.org/code_club/....
Want more practice on the concepts covered in Code Club? You can sign up for my weekly newsletter at shop.riffomonas.org/youtube to get practice problems, tips, and insights.
If you're interested in taking an upcoming 3 day R workshop be sure to check out our schedule at riffomonas.org/workshops/
You can also find complete tutorials for learning R with the tidyverse using...
Microbial ecology data: www.riffomonas.org/minimalR/
General data: www.riffomonas.org/generalR/
0:00 Joining data frames
3:52 full_join: returning all of the data
4:41 inner_join: returning the overlapping data
5:32 left_join and right_join: returning data in the left or right data frame
6:23 anti_join: returning the missing data
7:44 Using joins to filter data
9:50 Different methods of specifying which column to join by
11:07 Putting it all together
Пікірлер: 25
I have been trying to join my data for the last 4 days and finally! Thank you! I have been starting from the way beginning of your videos from 3 years ago. Thank you for sharing and being so detailed and adding extra functions and ideas that someone else may need to use.
@Riffomonas
4 ай бұрын
Im so glad to hear they’ve been helpful!
omg thank you!
Super useful explanation. The Anti-join function here is easier than that in SQL. Thanks for the video.
@Riffomonas
2 жыл бұрын
My pleasure! Thanks for watching Timmy
Amazing explanation! Thank you!!
@Riffomonas
2 жыл бұрын
Thanks for watching Sohila! 🤓
Cool.
The joins are also the way to mimic Excel’s much-loved VLOOKUP function
@Riffomonas
2 жыл бұрын
I feel like I need to do a “Pat relearns Excel” series 😂
Always great.
超喜欢你的讲解!!^_^
I remember really struggling to get merge to perform a left_join in my pre-tidyverse days
pat i love hadley so much for making my hard learned SQL skills relevant again by bringing them into R. As you mentioned, i also like to be explicit and always use the "by" argument, but this is also why i always use left_join. I feel like inner_join hides missing records from me and I want to know things are missing so I can handle those missing entries right away. Obviously you could look for missing data further along in your code but i'd rather just deal with it now. maybe there's a better way that I'm not aware of....
@Riffomonas
2 жыл бұрын
Hi Daniel - thanks for watching and writing. I *love* the joins. I get a lot out of seeing how other people use them
Cool video
@Riffomonas
2 жыл бұрын
Thanks dude
goatttttt
Hey Pat I am lost on the way. I want to know where did you come up with the ipsos dataset? I followed the link, I was totally lost on the way.
@Riffomonas
2 жыл бұрын
Hi Peter - I'm sorry the link above wasn't working but it is now. You can find it in the original video from this series (kzread.info/dash/bejne/o5Wf1c-KkcWzhaw.html) or on the github repository at raw.githubusercontent.com/riffomonas/vaccination_attitudes/main/august_october_2020.csv
How do you combine two data frames with different column names with the union function
What is the difference between merge(all=TRUE) and full_join()?
@Riffomonas
2 жыл бұрын
The *_join functions are the same functionality as provided by merge, but with a cleaner syntax
Would location %in% c(“Australia”, “Brazil”, …) not have worked here? I guess that is mute since you filter with a join later but still good to know that there is a short-cut.
@Riffomonas
4 ай бұрын
Both would work