R/mymean.R

Defines functions mymean

Documented in mymean

#' Test Driven Development
#'
#' A small example to see how far we come with implementing test driven development
#' in a very controlled situation with a definite and simple solution we can check.
#' @param x vector of numbers
#' @param na.rm boolean, should missing values in vector x be ignored?
#' @return average of x
#' @export
#' @importFrom stats na.omit
#' @importFrom utils head
mymean <- function(x, na.rm=T) {
  if (!is.numeric(x)) {
    warning(sprintf("Vector x is not numeric %s", paste(head(x), sep=",", collapse=",")))
    return(NA)
  }
  if (na.rm) x <- na.omit(x)
  sum(x)/length(x)
}
Stat585-at-ISU/worldle documentation built on April 4, 2023, 5:45 a.m.