R/timeDifference.R

Defines functions timeDifference

Documented in timeDifference

#' Time Difference
#'
#' @description This function takes as in put a numeric time value
#'   (\code{t0}) and a vector of numeric time values (\code{times}),
#'   and computes the difference in \code{times} relative to \code{t0}.
#'
#' @param t0    numeric scalar indicating the reference time point
#' @param times numeric vector of time points to be converted to
#'   time differences (in relation to \code{t0})
#'
#' @return a numeric vector of equal length to \code{times}, containing
#'   the computed time differences.
#'
#' @export
#'
#' @examples
#' dt(127, c(0,30,45,87,111, NA, 135, 155))

timeDifference <- function(t0, times){
  if(!(is.numeric(t0) & length(t0) == 1)) {
    stop("Parameter t0 must be a numeric scalar.")
  }
  stopifnot(is.numeric(times))
  return(t0 - times)
}
jchen032294/expSmooth documentation built on May 17, 2019, 1:29 p.m.