Skip to content
Prev 334490 / 398503 Next

why there is no quarters?

Hi,
Also,

library(zoo)
format.yearqtr(x)
identical(gsub("\\-"," ",xqq),format.yearqtr(x))
#[1] TRUE
A.K.
On Monday, December 16, 2013 8:01 AM, Marc Schwartz <marc_schwartz at me.com> wrote:

        
On Dec 15, 2013, at 6:11 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

            
Alternatively, ?cut.Date has "quarter" for the 'breaks' argument:

x <- seq(as.Date("2001/1/1"), as.Date("2010/1/1"), "months")

xq <- cut(x, breaks = "quarter")
[1] 2001-01-01 2001-01-01 2001-01-01 2001-04-01 2001-04-01 2001-04-01
[7] 2001-07-01 2001-07-01 2001-07-01 2001-10-01
37 Levels: 2001-01-01 2001-04-01 2001-07-01 2001-10-01 ... 2010-01-01


If you want to change the values to use "2001-Q2" or variants, you can do something like:

S <- c("01-01", "04-01", "07-01", "10-01")

xqq <- paste(substr(xq, 1, 5), "Q", match(substr(xq, 6, 10), S), sep = "")
[1] "2001-Q1" "2001-Q1" "2001-Q1" "2001-Q2" "2001-Q2" "2001-Q2"
[7] "2001-Q3" "2001-Q3" "2001-Q3" "2001-Q4"



See ?match, ?substr and ?paste


Regards,

Marc Schwartz


______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.