R/trimLeading.R

Defines functions trim_leading_values

Documented in trim_leading_values

#' trim leading repeats of a given value from a vector
#'
#' @param x vector of the same type as `value`
#' @param value value of which to remove leading repeats
#'
#' @author Charles Morefield
#' 
#' @examples
#' trim_leading_values(c(0,0,0,1,2,3))
#' trim_leading_values(c('a','a','d','e'), 'a')
#'
#' @return a vector trimmed of all leading values equal to `value`
#'
#' @export
trim_leading_values <- function(x, value = 0) {
    w <- which.max(cummax(x != value))
    x[seq.int(w, length(x))]
}
seandavi/sars2pack documentation built on May 13, 2022, 3:41 p.m.