Drop rows containing missing values in a column of nested data frames
Source:R/nest_drop_na.R
nest_drop_na.Rd
nest_drop_na()
is used to drop rows from each data frame in a column of
nested data frames.
Arguments
- .data
A data frame, data frame extension (e.g., a tibble), or a lazy data frame (e.g., from dbplyr or dtplyr).
- .nest_data
A list-column containing data frames
- ...
Columns within
.nest_data
to inspect for missing values. If empty, all columns within each dataframe in.nest_data
are used.
Value
An object of the same type as .data
. Each object in the column .nest_data
will have rows dropped according to the presence of NAs.
Details
nest_drop_na()
is a wrapper for tidyr::drop_na()
and maintains the functionality
of drop_na()
within each nested data frame. For more information on drop_na()
please refer to the documentation in 'tidyr'.
See also
Other tidyr verbs:
nest_extract()
,
nest_fill()
,
nest_replace_na()
,
nest_separate()
,
nest_unite()
Examples
gm <- gapminder::gapminder
# randomly insert NAs into the dataframe & nest
set.seed(123)
gm <-
gm %>%
dplyr::mutate(pop = dplyr::if_else(runif(nrow(gm)) >= 0.9,
NA_integer_,
pop))
gm_nest <- gm %>% tidyr::nest(country_data = -continent)
# drop rows where an NA exists in column `pop`
gm_nest %>%
nest_drop_na(country_data, pop)
#> # A tibble: 5 × 2
#> continent country_data
#> <fct> <list>
#> 1 Asia <tibble [364 × 5]>
#> 2 Europe <tibble [326 × 5]>
#> 3 Africa <tibble [572 × 5]>
#> 4 Americas <tibble [273 × 5]>
#> 5 Oceania <tibble [23 × 5]>