Search code examples
rdatedate-formatreformatas.yearqtr

Turn character YYYY-Q1 into date


I would like to turn a character variable formatted as YYYY-QQ, so for example 2010-Q1, into something I can use as a date. I have played around with as.yearqtr, but haven't could only figure out the output format. I haven't been been able to define the input format though.

Edit:

Has also been answered here.


Solution

  • You have to use the right format in as.yearqtr formula like this:

    library(zoo)
    x<-"2010-Q1"
    as.yearqtr(x, format = "%Y-Q%q")
    [1] "2010 Q1"