R/decade.R

Defines functions dtt_decade.Date dtt_decade

Documented in dtt_decade dtt_decade.Date

#' Decade
#'
#' @inheritParams params
#'
#' @return A integer vector of the decade.
#' @export
#'
#' @examples
#' dtt_decade(as.Date(c("2001-01-01", "2015-12-13")))
dtt_decade <- function(x, ...) {
  UseMethod("dtt_decade")
}

#' @describeIn dtt_decade Decade a Date vector
#' @export
dtt_decade.Date <- function(x, ...) {
  chk_unused(...)
  year <- dtt_year(x)
  year <- year / 10
  year <- floor(year)
  year <- year * 10
  year <- as.integer(year)
  year
}

Try the dttr2 package in your browser

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

dttr2 documentation built on Sept. 26, 2024, 1:06 a.m.