[R] plot a single frequency of a ts object
William Dunlap
wdunlap at tibco.com
Thu Nov 7 03:13:20 CET 2013
> y2 <- ts(x2, frequency=4, start=c(1952,1))
> y2w<-ts(y2[seq(1,61,by=4)],frequency=1,start=1952)
I think it is simpler to compute y2w using the window() function, which
figures out the right call to seq() for you:
window(y2, frequency=1, start=c(1952,1)) # use c(1952,2) for springs, etc.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Jim Lemon
> Sent: Wednesday, November 06, 2013 5:54 PM
> To: Stefano Sofia
> Cc: r-help at r-project.org
> Subject: Re: [R] plot a single frequency of a ts object
>
> On 11/07/2013 04:56 AM, Stefano Sofia wrote:
> > Dear list users,
> > I transformed two vectors of seasonal data in ts objects of frequency 4:
> >
> > y1<- ts(x1, frequency=4, start=c(1952,1))
> > y2<- ts(x2, frequency=4, start=c(1952,1))
> >
> > In this way Qtr1 corresponds to Winters, Qtr2 corresponds to Springs and so on.
> > I would like to plot on the same graph both y1 and all the Winters of y2.
> > I am not able to find an easy and straightforward way to do that.
> > Could somebody please help me in this?
>
> Hi Stefano,
> This may do what you want:
>
> x1<-runif(64,1,4)
> x2<-runif(64,2,5)
> y1 <- ts(x1, frequency=4, start=c(1952,1))
> y2 <- ts(x2, frequency=4, start=c(1952,1))
> plot(y1,ylim=c(1,5))
> y2w<-ts(y2[seq(1,61,by=4)],frequency=1,start=1952)
> lines(y2w)
>
> Jim
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list