naniar icon indicating copy to clipboard operation
naniar copied to clipboard

consider replace_na_with functions

Open njtierney opened this issue 7 years ago • 1 comments

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

njtierney avatar Jan 23 '18 03:01 njtierney

Extant functions include dplyr::coalesce and hutils::coalesce (by me).

HughParsonage avatar Jan 28 '18 01:01 HughParsonage

We should re-export coalesce and provide documentation on how to use it, alongside the replace_with_na function

njtierney avatar Apr 23 '23 22:04 njtierney