In R, it\'s possible to format POSIXlt date-time objects as a month:
format(Sys.time(), format=\'%Y-%m\')
Is there a way to do the same thi
Let Q1 be DJF; Q2, MAM; etc. then:
seasonal.quarters <- function(x) {
x <- as.POSIXlt(x)
x$mon <- (x$mon + 1) %% 12
quarters(x)
}
options(stringsAsFactors=FALSE)
nonleap.year <- seq(from=as.POSIXct('2013-1-1'), to=as.POSIXct('2014-1-1'), by='day')
d <- data.frame(ms=months(nonleap.year), qs=seasonal.quarters(nonleap.year))
by(d, INDICES=list(d$qs), FUN=function(x) unique(x$ms))
# : Q1
# [1] "January" "February" "December"
# -------------------------------------
# : Q2
# [1] "March" "April" "May"
# -------------------------------------
# : Q3
# [1] "June" "July" "August"
# -------------------------------------
# : Q4
# [1] "September" "October" "November"
leap.year <- seq(from=as.POSIXct('2016-1-1'), to=as.POSIXct('2017-1-1'), by='day')
d <- data.frame(ms=months(leap.year), qs=seasonal.quarters(leap.year))
by(d, INDICES=list(d$qs), FUN=function(x) unique(x$ms))
# : Q1
# [1] "January" "February" "December"
# -------------------------------------
# : Q2
# [1] "March" "April" "May"
# -------------------------------------
# : Q3
# [1] "June" "July" "August"
# -------------------------------------
# : Q4
# [1] "September" "October" "November"