[R] changing the time base in a ts

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


Dr Carbon wrote:

> Sorry, what I meant was that I want dat.sub[1] to line up with dat[7],
> dat.sub[2] to line up with dat[19], dat.sub[3] with dat[12+12+7],
> etc...


Sorry, I haven't read your mail carefully enough:

   plot(dat)
   plot(x = time(dat.sub, offset = 0.5), y = dat.sub,
     type = "b", xy.labels = FALSE, xlim = c(1980, 2000))

Uwe Ligges


> 
> On Mon, 31 Jan 2005 18:34:55 +0100, Uwe Ligges
> <ligges at statistik.uni-dortmund.de> wrote:
> 
>>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