powered by
This function takes an object and sets all non-missing values to zero, while leaving missing values unchanged.
set_zero(x)
An object of the same type as x with all originally non-missing elements replaced by zero.
x
A vector or other object for which is.na() and subsetting with [] are defined (e.g., vector, data frame, SpatRaster).
is.na()
[]
# Example with a numeric vector vec <- c(1, 2, NA, 4, NA, 5) set_zero(vec)
Run the code above in your browser using DataLab