R/percent_peak.R

Defines functions percent_peak

#' percent_peak
#'
#' Calculate the % of the peaks compared to the baseline
#'
#' @param x vector of trace data
#' @param ... additional parameters to pass to find_peaks
#'
#' @return vector containing the peak %
#' @export
#' @importFrom baseline baseline
#' @examples
#' data(ca_flux)
#' ph <- percent_peak(ca_flux$Mean1)
percent_peak <- function(x, ...) {
  # find the location of the peaks
    peaks <- find_peaks(x, ...)
      # find the baseline for each peak
    bl <- baseline(as.matrix(t(x)), method = 'rolling', wm = 5, ws = 5)
      # divide the baseline from the peak value and multiply by 100
    percent <- (x[peaks] / bl@baseline[peaks]) * 100
    return(percent)
}
VanAndelInstitute/cardiocyte documentation built on July 17, 2020, 8:27 p.m.