nest_fill()
is used to fill missing values in selected columns of nested data
frames using the next or previous entries in a column of nested data frames.
Usage
nest_fill(
.data,
.nest_data,
...,
.direction = c("down", "up", "downup", "updown")
)
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
- ...
<
tidy-select
> Columns to fill.- .direction
Direction in which to fill missing values. Currently either "down" (the default), "up", "downup" (i.e. first down and then up) or "updown" (first up and then down).
Value
An object of the same type as .data
. Each object in the column .nest_data
will have the chosen columns filled in the direction specified by .direction
.
Details
nest_fill()
is a wrapper for tidyr::fill()
and maintains the functionality
of fill()
within each nested data frame. For more information on fill()
please refer to the documentation in 'tidyr'.
See also
Other tidyr verbs:
nest_drop_na()
,
nest_extract()
,
nest_replace_na()
,
nest_separate()
,
nest_unite()
Examples
set.seed(123)
gm <-
gapminder::gapminder %>%
dplyr::mutate(pop = dplyr::if_else(runif(dplyr::n()) >= 0.9,
NA_integer_,
pop))
gm_nest <- gm %>% tidyr::nest(country_data = -continent)
gm_nest %>%
nest_fill(country_data, pop, .direction = "down")
#> # A tibble: 5 × 2
#> continent country_data
#> <fct> <list>
#> 1 Asia <tibble [396 × 5]>
#> 2 Europe <tibble [360 × 5]>
#> 3 Africa <tibble [624 × 5]>
#> 4 Americas <tibble [300 × 5]>
#> 5 Oceania <tibble [24 × 5]>