R/calc_peak_density.r

Defines functions calc_peak_density

Documented in calc_peak_density

#' Peak density value computation
#'
#' @description Computation of the peak value, of a density function with a gaussian kernel.
#'
#' @eval arg_vector("x","numeric")
#'
#' @return A numeric single value with the computed peak density value.
#' @export
#'
#' @examples
#'
#' x <- rnorm(100)
#'
#' plot(density(x))
#'
#' calc_peak_density(x)
#'

calc_peak_density <- function(x){

  stopifnot(is.numeric(x), length(x) > 1)

  d <- stats::density(stats::na.omit(x))

  output <- d$x[which.max(d$y)]

  return(output)

}
vbfelix/relper documentation built on May 10, 2024, 10:50 p.m.