R/maximum.R

#' Maximum
#'
#' This function takes a single numeric vector and returns the maximum value in the vector.
#'
#' @param x Numeric vector of values
#'
#' @return Maximum value
#' @export
#'
#' @examples
#' x <- 1:10
#' maximum(x)
maximum <- function(x){

  check_numeric_vector(x)  # Check that the input is a single numeric vector

  n <- length(x)  # Number of elements in x
  x_max <- x[1]

  for (i in 2:n){

    if (x[i] > x_max){

      x_max <- x[i]

    }

  }

  return(x_max)

}
AshleyDennisHenderson/data.summary documentation built on June 12, 2019, 11:25 a.m.