How to get years from the time series index when the base time series has a monthly frequency?

I would like to extract the years from the time series index (the base time series has a monthly frequency). The reason I want to do this is to create an annual axis, for example.

plot(myts)
axis(1, at = year(time(myts)), labels = FALSE)
# note I know 'year()' does not work :)

because if I just draw it, R arbitrarily (?) creates a time axis. It often happens that a two or even a 5-year axis is sometimes not suitable.

tsp(myts) 
[1] 1966.000 1974.917   12.000
0
source share
2 answers

I found my own solution. Maybe this also helps someone else. In addition, I think this is not too smart ... so I look forward to your suggestions.

 axis(1, at = start(time(myts))[1]:end(time(myts))[1], labels = TRUE)

EDIT: Found a more elegant solution:

require(zoo)
x <- as.yearqtr("1991 Q1")
format.Date(x,"%Y")

@matty T ts (. ).

+2

, (ts), window:

window(myts,start="*beginyear*",end="*endyear*")

, , :

http://r.789695.n4.nabble.com/Year-and-Month-extraction-from-Date-object-td904011.html

Matt

0

All Articles