R/cum_lag.R

Defines functions cum_lag

Documented in cum_lag

#' cum_lag
#' 
#' @description helpful function to cumulate information.
#' 
#' @param x numeric vector for which lag variable should be computed
#' @param n_lag size of lag window
#'
#' @return return numeric vector.
cum_lag <- function(x, n_lag){
  result <- 0
  for(i in 1:n_lag){
    result <- result + ifelse(is.na(lag(x, i)), 0, lag(x, i))
  }
  return(result)
}

Try the PheVis package in your browser

Any scripts or data that you put into this service are public.

PheVis documentation built on Oct. 20, 2023, 9:08 a.m.