Reputation: 641
I am trying to format my x axis.
Say I want to get "MM.YYYY" for every value in x axis in order to use it in axis()
, so I:
> test <- ts (c(12,23,45,31,15), start=2012, frequency = 12)
> time(test)
Jan Feb Mar Apr May
2012 2012.000 2012.083 2012.167 2012.250 2012.333
My question is, how to convert from say "2012.333" to "05.2012". I tried with:
> strftime(strptime(time(test),"%?.%?"),"%m.%Y")
but I ignore the appropriate variables in "%?.%?"
Upvotes: 3
Views: 111
Reputation: 270020
Try this:
> library(zoo)
> format(as.yearmon(time(test)), "%m.%Y")
[1] "01.2012" "02.2012" "03.2012" "04.2012" "05.2012"
Upvotes: 3