naniar
naniar copied to clipboard
consider replace_na_with functions
The creation of the replace_with_na
functions has been nice - and the scoped variants (_at
, _if
, and _all
) have been useful.
I think it would be useful to have functions that go the other way - from NA to a value.
This could be called replace_na_with
- to provide a more direct complement to replace_with_na
.
This is of interest to users, see this SO question
This could be written something like this:
replace_na_with <- function(vars, value) mutate_at(vars, funs(replace(., is.na(.), value)))
Extant functions include dplyr::coalesce
and hutils::coalesce
(by me).
We should re-export coalesce
and provide documentation on how to use it, alongside the replace_with_na
function