R/doy-decimal.R

Defines functions dtt_doy_decimal.POSIXct dtt_doy_decimal.Date dtt_doy_decimal

Documented in dtt_doy_decimal

#' Day of the Year Decimal
#'
#' @inheritParams params
#' @param x A Date or POSIXct vector.
#'
#' @return A numeric vector between 0 and 366 of the day of the year.
#' @family decimal
#' @seealso [dtt_doy()]
#' @export
#'
#' @examples
#' dtt_doy_decimal(Sys.Date())
dtt_doy_decimal <- function(x, ...) {
  UseMethod("dtt_doy_decimal")
}

#' @export
dtt_doy_decimal.Date <- function(x, ...) {
  as.numeric(dtt_doy(x))
}

#' @export
dtt_doy_decimal.POSIXct <- function(x, ...) {
  dtt_doy(x) + dtt_hour_decimal(x) / 24
}

Try the dttr2 package in your browser

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

dttr2 documentation built on Nov. 14, 2023, 5:10 p.m.