nest_replace_na {nplyr}R Documentation

Replace NAs with specified values in a column of nested data frames

Description

nest_replace_na() is used to replace missing values in selected columns of nested data frames using values specified by column.

Usage

nest_replace_na(.data, .nest_data, replace, ...)

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

replace

A list of values, with one value for each column in that has NA values to be replaced.

...

Additional arguments for tidyr::replace_na() methods. Currently unused.

Details

nest_replace_na() is a wrapper for tidyr::replace_na() and maintains the functionality of replace_na() within each nested data frame. For more information on replace_na() 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 NAs replaced in the specified columns.

See Also

Other tidyr verbs: nest_drop_na(), nest_extract(), nest_fill(), 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_replace_na(.nest_data = country_data,
                  replace = list(pop = -500))

[Package nplyr version 0.2.0 Index]