[R] changing the time base in a ts

Dr Carbon drcarbon at gmail.com
Mon Jan 31 18:04:12 CET 2005


I'm probably apporaching this all wrong to start but....

Suppose I have a monthly time series and I want to compute the mean of
months 6,7, and 8. I want to plot the original time series and the
seasonal time series, one above the other. When I do that as below the
time series don't line up for reasons that are obvious. How can I
change the base of the seasonal time series so I can make my plots
line up? That is, I want the points for the seasonal plot to line up
with cycle 6 of the first plot.

Thanks. 


dat <- ts(rnorm(12*20), start = c(1980,1), frequency = 12)
plot(dat)
dat.sub <- dat
dat.sub[cycle(dat.sub) < 6] <- NA
dat.sub[cycle(dat.sub) > 8] <- NA
dat.sub <- aggregate(dat.sub, nfrequency = 1, FUN = mean, na.rm = T)
tsp(dat)
tsp(dat.sub)
par(mfrow = c(2, 1))
plot(dat)
plot(dat.sub, type = "b")




More information about the R-help mailing list