nest_replace_na: Replace NAs with specified values in a column of nested data...

View source: R/nest_replace_na.R

nest_replace_naR Documentation

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


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


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



A data frame, data frame extension (e.g., a tibble), or a lazy data frame (e.g., from dbplyr or dtplyr).


A list-column containing data frames


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.


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


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


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

nplyr documentation built on Feb. 16, 2023, 7:24 p.m.