R/datesManip.R

Defines functions date2summer date2month date2wy date2year

Documented in date2month date2summer date2wy date2year

#' @title Functions to transform dates into other useful information
#' @name dates transformation 
#' @param datevec a vetor of dates (\code{class(datevec)} must be Date)
#' @param endMonth the month which indicates the end of the Water Year or Summer Season (default is 9, September)
#' @param begMonth the month which indicates the beginning of summer  (default is 4, April)
#' @return The year, water year or month from the input date. Or a 0-1 indicator of summer.
#' @export
date2year <- function(datevec) as.numeric(substring(datevec,first=1,last=4)) 
#' @name dates transformation
#' @family manipulate dates
#' @export
date2wy <- function(datevec, endMonth = 9) as.numeric(substring(datevec,first=1,last=4)) - 1*as.numeric(as.numeric(substring(datevec,first=6,last=7) ) <= endMonth)
#' @name dates transformation
#' @family manipulate dates
#' @export
date2month <- function(datevec)  as.numeric(substring(datevec,first=6,last=7))
#' @name dates transformation
#' @family manipulate dates
#' @export
date2summer <- function(datevec, begMonth = 4, endMonth = 9) as.numeric(date2month(datevec) > (begMonth-1) & date2month(datevec) <= endMonth)
ilapros/ilaprosUtils documentation built on April 6, 2023, 4:44 a.m.