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 →

# filter

## This lesson is locked

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.

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

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

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

``````nhanes %&gt;%
``````

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

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

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

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

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

#### Josh Gutwill

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

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

``````nhanes %&gt;%
filter(marital_status %in% c("Divorced","Separated", "Widowed")) %&gt;%
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

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.