Skip to content
R for the Rest of Us: A Statistics-Free Introduction comes out June 25th. Or you can read the online version today. Check it out →
R for the Rest of Us Logo

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

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

Complete the filter sections of the data-wrangling-and-analysis-exercises.Rmd file.

Learn More

General Data Wrangling and Analysis Resources

Because most material that discusses data wrangling and analysis with the dplyr packges does so in a way that covers all of the verbs discussed in this course, I have chosen not to separate them by lesson. Instead, here are some helpful resources for learning more about all of the tidyverse verbs discussed in this course:

Chapter 5 of R for Data Science

RStudio Cloud primer on working with data

Tidyverse for Beginners by Danielle Navarro

Learning Statistics with R by Danielle Navarro

Introduction to the Tidyverse by Alison Hill

A gRadual intRoduction to data wRangling by Chester Ismay and Ted Laderas

Working in the Tidyverse by Desi Quintans and Jeff Powell

Christine Monnier video tutorials on dplyr

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

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

Catherine Roller White

Catherine Roller White

March 27, 2021

There is a line in the data-wrangling-and-analysis-exercises.Rmd file that says: "We can use Use , for numeric data." I think the placement of the equals sign may need to change for "greater or equal than" (i.e., '=>' should be '>=').

Vuk Sekicki

Vuk Sekicki

March 27, 2021

nhanes %>%
    filter(drop_na(days_phys_hlth_bad)) %>%
    select(phys_active_days, days_phys_hlth_bad)

returns: Error: Problem with filter() input ..1. x no applicable method for 'drop_na' applied to an object of class "c('double', 'numeric')" ℹ Input ..1 is drop_na(days_phys_hlth_bad). Run rlang::last_error() to see where the error occurred.

Hana Hanfi

Hana Hanfi

April 7, 2021

I'm getting an error that "drop_na" wasn't found even though I previously loaded "dplyr" into the library. Should I have loaded another function?

Zach Tilton

Zach Tilton

August 19, 2021

Received an error code on the last exercise:

Error in drop_na(., days_phys_hlth_bad) : could not find function "drop_na"

dplyr is loaded. Not sure what is happening here. Moving forward with !is.na for the time being. Thanks.

Ekerette Udoh

Ekerette Udoh

September 30, 2021

nhanes %>% filter(Education == "College Grad") %>% select(Education, MaritalStatus)

When running the code above Education and MaritalStatus displays just fine. But when I add the second filter function as below I get an error message.

nhanes %>% filter(Education == "College Grad") %>% filter(MaritalStatus %n% c("Divorced", "Separated", "Widowed")) %>% select(Education, MaritalStatus)

Nathan Welsch

Nathan Welsch

January 17, 2022

Is there a "rule of thumb" or useful way of remembering what needs quotes?

Josh Gutwill

Josh Gutwill

October 4, 2022

I'm wondering if you know why one needs to concatenate multiple observations in the filter function. For example, here's a correct use of filter: filter(marital_status %in% c("Divorced", "Separated", "Widowed")) From what I understand of the concatenate function (from Excel), wouldn't that basically mean R is looking at each observation in marital_status and seeing if that observation can be found anywhere inside "DivorcedSeparatedWidowed"? But when I try it without concatenating by doing this: filter(marital_status %in% ("DivorcedSeparatedWidowed")) I get an error message. Maybe the answer is "That's just how R works," but I'm trying to build a solid mental model for these functions, so if there's anything more to it, I'd love to better understand. Thanks!

Ellen Wilson

Ellen Wilson

October 6, 2022

I'm puzzled because in your video, it looks like there are code chunks that say "Your code here" (or something like that), but when I go to the file, the code is already complete for all the code chunks. This has actually been the case for the past few sections, and looks like it is for the next one, too.

Julieth Silao

Julieth Silao

November 6, 2022

nhanes %>%
  filter(education == "Collage Grad") %>%
  filter(marital_status %in% c("Divorced","Separated", "Widowed")) %>%
  select(education, marital_status)

A tibble:0 × 2

hello David

when i filter education and marital status , i didnt get any table instead A tibble.0x 2 can i help

Chelsea Ruder

Chelsea Ruder

March 29, 2023

I can't seem to get the drop an or !is.na functions to work. oregon_respondents % select_all() %>% filter(!is.na(ip_address))

When I run this code, there are still blanks for ip_address.