This commit is contained in:
@@ -146,4 +146,20 @@ race_short_names <- function(x) {
|
||||
return(x)
|
||||
}
|
||||
|
||||
#' Sum a numeric that contains missing values and ignore missing values
|
||||
#'
|
||||
#' @param x a numeric vector
|
||||
#'
|
||||
#' @return the sum, ignoring any missing values
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' x <- c(2, NA, 4, 9)
|
||||
#' na_sum(x) # 15
|
||||
na_sum <- function(x) {
|
||||
stopifnot(is.numeric(x))
|
||||
message("Taking a sum with missing values equal to 0, be careful 🐲")
|
||||
x <- na_zero(x)
|
||||
return(sum(x))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user