defaultIfZero | R Documentation |
Return the given object or a default value if the object is 0 (zero)
defaultIfZero(x, default, count = FALSE)
x |
vector possibly containing zeroes |
default |
value to be used instead of zero |
count |
if |
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.
defaultIfNA, defaultIfNULL
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.