Turn character YYYY-Q1 into date

1.2k views Asked by At

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.

1

There are 1 answers

0
Terru_theTerror On BEST ANSWER

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"