r - How to change character string into yearqtr -


i have dataseries 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 change index 'yearqtr' class? tried doing as.date , as.character. throwing error saying: error in chartodate(x) : character string not in standard unambiguous format.

can please help?

1) remove , including minus , use as.yearqtr appropriate percent codes:

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

2) works , shorter:

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

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -