Below is the code:
library(tidyverse) df <- tibble( ~col1, ~col2, ~col3, 1, 2, 3, 1, NA, 3, NA, 2, 3 )
I can remove all NA abservations with the help of drop_na():
df %>% drop_na()
Or remove all NA in a single column (col1 for example):
df %>% drop_na(col1)
Why I cannot just use a regular != filter pipe ?
df %>% filter(col1 != NA)
Why do we use a special function from tidyr to remove NAs?
5 answers
R is unaware of the context of your analysis.
Essentially, it does not permit comparison operators to treat NA as a valid value.
Are you considering a career in data analysis? Our Data Analyst Certification Course will provide you with the essential tools and techniques for success.
Try this:
df %>% filter(!is.na(col1))
This was simple, direct and perfect...thank you!
In this case, na.omit(airquality$Ozone) will yield the values that are not null.
Afterward, can we supply the list of positions to the filtering function?
flight %>% select(FL_DATE, CARRIER, ORIGIN, ORIGIN_CITY_NAME, ORIGIN_STATE_ABR, DEP_DELAY, DEP_TIME, ARR_DELAY, ARR_TIME) %>% filter(!is.na(ARR_DELAY))
Thanks, that worked