nest_fill {nplyr}R Documentation

Fill missing values in a column of nested data frames

Description

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).

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'.

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.

See Also

Other tidyr verbs: nest_drop_na(), nest_extract(), nest_replace_na(), nest_separate(), nest_unite()

Examples

set.seed(123)
gm <- gapminder::gapminder %>% mutate(pop = if_else(runif(n()) >= 0.9,NA_integer_,pop))
gm_nest <- gm %>% tidyr::nest(country_data = -continent)

gm_nest %>% nest_fill(.nest_data = country_data,pop,.direction = "down")

[Package nplyr version 0.2.0 Index]