0
votes

I have a dataseries which looks like:

gdp <- structure(c(4.61992172242418, 4.6566625355851, 4.36946546173971, 
4.84162425714203, 5.27383573389955, 5.13243064162054, 4.95781801538584, 
5.26294884122223, 12.5001588735103, 14.5451731219964, 10.3624546107312, 
10.3243661354426), .Dim = c(4L, 3L), .Dimnames = list(NULL, c("in.gdp.fc", 
"in.gdp.real", "in.gdpnagri")), index = c("Apr-Jun 2012", 
"Jul-Sep 2012", "Oct-Dec 2012", "Jan-Mar 2013"), class = "zoo")`

How can I change the index into 'yearqtr' class? I tried doing as.Date and then as.character. It is throwing up some error saying: Error in charToDate(x) : character string is not in a standard unambiguous format.

Can someone please help?

1

1 Answers

0
votes

1) Remove everything up to and including the minus and then use as.yearqtr with the appropriate percent codes:

library(zoo)
gdp.yq <- gdp
index(gdp.yq) <- as.yearqtr(sub(".*-", "", index(gdp)), "%b %Y")

2) This also works and is a shorter:

library(zoo)
gdp.yq <- gdp
index(gdp.yq) <- as.yearqtr(index(gdp), "%b-%b %Y")