[R] changing the time base in a ts

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Jan 31 18:34:55 CET 2005


Dr Carbon wrote:
> 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")


  plot(dat)
  plot(dat.sub, type = "b", xlim=c(1980, 2000))

Uwe Ligges


> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list