defaultIfZero: Default Value if Object is 0 (zero)

View source: R/default.R

defaultIfZeroR Documentation

Default Value if Object is 0 (zero)

Description

Return the given object or a default value if the object is 0 (zero)

Usage

defaultIfZero(x, default, count = FALSE)

Arguments

x

vector possibly containing zeroes

default

value to be used instead of zero

count

if TRUE (the default is FALSE) the number of replaced values is returned in the attributes count

Value

x if x is not 0 and default otherwise. The returned object has an attribute count containing the number of values that have been set to the default value.

See Also

defaultIfNA, defaultIfNULL

Examples

defaultIfZero(c(1, 2, 0, 4, 5, 0, 6), NA) # returns the default value (NA) 
(out <- defaultIfZero(1:6, NA, count = TRUE)) # returns the "actual" values

# The number of values that were zero is returned in the attribute "count" 
attr(out, "count")
  

KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.