Data Science Desktop Survival Guide
by Graham Williams |
|||||
Selecting Rows |
20200419 Rows from a data frame can be dplyr::filter()'ed using specific conditions. The rows in the resulting data frame will be those for which the condition is true.
ds %>%
filter(max_temp >= mean(max_temp, na.rm=TRUE))
To select rows that have missing values, for example, use dplyr::filter() with purrr::pmap_lgl() to map base::is.na() for base::any() column in the row. In the following example we count the number with missing values using base::nrow(), formatted nicely using scales::comma():
|
ds %>%
select(-date) %>% filter(pmap_lgl(., ~any(is.na(c(...))))) %>% nrow() %>% comma() %>% cat("rows have missing values.\n")
|