Learn R Programming

mrangr (version 1.0.1)

set_zero: Set Non-Missing Values to Zero

Description

This function takes an object and sets all non-missing values to zero, while leaving missing values unchanged.

Usage

set_zero(x)

Value

An object of the same type as x with all originally non-missing elements replaced by zero.

Arguments

x

A vector or other object for which is.na() and subsetting with [] are defined (e.g., vector, data frame, SpatRaster).

Examples

Run this code
# 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