Skip NAs when running a function on a vector
skip_na.Rd
skip_na()
is a helper function related to na.omit()
. It runs a function
f
on a vector that may contain NAs or NaNs, skipping all the NAs, and
returns the results as a vector of the same length as x
with the NAs
in the same places.
Examples
x <- c(1,2,3,NA,4,5,6,NA,7,8)
skip_na(x, cumsum)
#> [1] 1 3 6 NA 10 15 21 NA 28 36
# should return a vector the same length as x with NAs in position 4 and 8