Subset a data frame by excluding missing cases AND certain values

Viewed 216

I have a dataset where my key Variable is scored from 1 to 10 and data exists for all but one case for this variable. I want to analyse data with scores equal or above 8 and ignoring the one missing case.

I managed to do the above by subsetting TWICE but ideally I would like to do all of this in one command.

Data2<-Data1[(Data1$Variable>=8),]

Data3<-Data2[!is.na(Data2$Variable),]

How can I combine the above to keep things simple?

Many thanks.

1 Answers

You can do this with the tidyverse package and the filter() function quite easily:

library(tidyverse)

Data2 <- filter(Data1, Variable >= 8, !is.na (Variable))
Related