R/peaks.R

Defines functions peaks

Documented in peaks

#' Peaks function
#'
#' This function finds the local maxima in a data frame
#' @param series the series of interest
#' @param span Length of search. Defaults to 3.
#' @keywords peak local maxima series
#' @export
#' @examples
#' x <- c(1:5,4,8:2,9,1)
#' peaks(x)

peaks <- function(series, span = 3) {
  z <- embed(series, span)
  s <- span%/%2
  v <- max.col(z) == 1 + s
  result <- c(rep(FALSE, s), v)
  return(result[1:(length(result) - s)])
}
lingwhatics/daleym documentation built on May 21, 2019, 6:16 a.m.