R/doy.R

Defines functions doy

Documented in doy

#' Compute the day of the year from date
#' 
#' Given an .Rdate object, this function computes the day of the year (from 1-366)
#'
#' @param x Rdates to compute the day of the year
#' 
#' @keywords utilities
#' @export
doy <- function(x) {
  out <- rep(NA, length(x))
  iix <- !(!is.finite(x) | is.na(x))
  if (any(iix)){
    year <- format(x[iix], '%Y')
    refdate <- as.Date(paste(year, '01', '01', sep='-'))
    out[iix] <- julian(x[iix]) - julian(refdate) + 1
  }
  return(out)
}
jonasbhend/geoutils documentation built on May 19, 2019, 7:27 p.m.