R/sparse_replace_na.R
sparse_replace_na.Rd
Replace NAs with specified values in sparse vectors
sparse_replace_na(x, replace)
A sparse vector.
This function, as with any of the other helper functions assumes that the
input x
is a sparse numeric vector. This is done for performance reasons,
and it is thus the users responsibility to perform input checking.
The replace
is likewise not type or length checked.
The output type will match the values after coercion happens during replacement.
sparse_replace_na(
sparse_double(c(10, NA, 11), c(1, 5, 10), 10),
5
)
#> [1] 10 0 0 0 5 0 0 0 0 11
sparse_replace_na(
sparse_integer(c(10L, NA, 11L), c(1, 5, 10), 10),
5L
)
#> [1] 10 0 0 0 5 0 0 0 0 11
sparse_replace_na(
sparse_character(c("A", NA, "E"), c(2, 5, 10), 10),
"missing"
)
#> [1] "" "A" "" "" "missing" "" ""
#> [8] "" "" "E"