sum_ignore_NA: Sum ignoring NAs

View source: R/misc_fns.R

sum_ignore_NAR Documentation

Sum ignoring NAs

Description

Will sum values returning NA only if all values are NA, otherise will ignore

Usage

sum_ignore_NA(...)

Arguments

...

numbers or vectors to be summed. Must be type logical or numeric.

Details

this function will provide vectorized sums with NAs ignored unless only NAs are present

Value

a numeric vector of the same length as the arguments

Examples

# ignores NA
sum_ignore_NA(2, 3, NA)
# returns NA if all values are NA
sum_ignore_NA(NA, NA, NA)

# returns vectorized sums

x <- c(1, 2, NA)
y <- c(1:3)
sum_xy <- sum_ignore_NA(x, y)
data.frame(x, y, sum_xy)

x <- c(1, 2, NA)
y <- c(1, 2, NA)
sum_xy <- sum_ignore_NA(x, y)
data.frame(x, y, sum_xy)

CIDA-CSPH/CIDAtools documentation built on Sept. 18, 2023, 10:55 a.m.