10.14 Filter Rows Having Missing Values
20201202 To select the rows from a dataset which have missing values in any of the columns across the dataset we dplyr::filter() dplyr::across() tidyselect::everything() that base::is.na() and reduce it within the dplyr::filter() using the or operator. In the example we randomly sample a few rows and columns to show the result.
ds %>%
filter(across(everything(), is.na) %>% reduce(`|`)) %>%
sample_frac() %>%
select(date, location, sample(3:length(vars), 4))## # A tibble: 196,937 × 6
## date location wind_dir_3pm temp_9am risk_mm wind_speed_3pm
## <date> <chr> <ord> <dbl> <dbl> <dbl>
## 1 2022-05-11 Dartmoor NNE 9.3 2 6
## 2 2019-08-15 Cairns SE 21.1 0 26
## 3 2022-09-13 Mildura N 10.6 0 9
## 4 2025-10-31 Williamtown ESE 20 3.2 22
## 5 2013-06-06 Albany SSW 14.4 1.6 6
## 6 2023-11-10 NorfolkIsland SE 18.9 0 20
## 7 2025-12-06 NorfolkIsland SE 21.2 0 20
## 8 2020-03-12 Newcastle <NA> 20.4 0 NA
## 9 2023-03-14 Nhil NW 17.4 0 11
## 10 2014-11-13 Witchcliffe SE 13.5 0.2 30
## # ℹ 196,927 more rows
If you find this curated material useful then you can consider a donation to support it's ongoing availability and give you access to the PDF version of this book. The material has been scoped up by Generative AI without permission or any kind of recompense so do consider a donation if you can afford it. Unlike Generative AI your access to this materials is freely given. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Togaware has a 30 year tradition of making popular open source software which includes sold privacy preserving productivity apps, rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0