[R] plot two time series with different length and different starting point in one figure.

arun smartpink111 at yahoo.com
Tue Jan 22 17:28:00 CET 2013


Hi,

dateA<-seq.Date(as.Date("1jan2012",format="%d%b%Y"),as.Date("31Dec2012",format="%d%b%Y"),by="day")
 dateB<-seq.Date(as.Date("1Mar2012",format="%d%b%Y"),as.Date("30Nov2012",format="%d%b%Y"),by="day")
set.seed(15)
 A<-data.frame(dateA,value=sample(1:300,366,replace=TRUE))
 set.seed(25)
 B<-data.frame(dateB,value=sample(1:300,275,replace=TRUE))
res<-merge(A,B,by.x="dateA",by.y="dateB") #it works


A.K.



----- Original Message -----
From: "Yuan, Rebecca" <rebecca.yuan at bankofamerica.com>
To: 'PIKAL Petr' <petr.pikal at precheza.cz>
Cc: R help <r-help at r-project.org>
Sent: Tuesday, January 22, 2013 10:36 AM
Subject: Re: [R] plot two time series with different length and different starting point in one figure.

Hello Petr,

As the time series have the same column names, I got the error message like:


--------------------------------------------------------------------
> m1<-merge(A, B, by.x = "time", by.y = "balance")
Error in fix.by(by.x, x) : 'by' must specify uniquely valid column(s)
--------------------------------------------------------------------

To plot A and B in one plot is to compare the difference between them...

Any other thoughts?

Thanks,

Rebecca


-----Original Message-----
From: PIKAL Petr [mailto:petr.pikal at precheza.cz] 
Sent: Tuesday, January 22, 2013 10:28 AM
To: Yuan, Rebecca; R help
Subject: RE: plot two time series with different length and different starting point in one figure.

Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- 
> project.org] On Behalf Of Yuan, Rebecca
> Sent: Tuesday, January 22, 2013 4:07 PM
> To: R help
> Subject: [R] plot two time series with different length and different 
> starting point in one figure.
> 
> Hello,
> 
> I do have two different time series A and B, they are different in 
> length and starting point. A starts in Jan, 2012 and ends in Dec, 2012 
> and B starts in March, 2012 and ends in Nov, 2012.
> 
> How can I plot those two series A and B in the same plot? I.E., from 
> Jan. 2012 - Feb, 2012, it would have one data point from A and from 
> Mar, 2012-Nov, 2012, it would have two data points from A and B, and 
> in December 2012, it would have one data point from A.

Merge those 2 series.

?merge

Regards
Petr

> 
> Thanks very much!
> 
> Cheers,
> 
> Rebecca
> 
> 
> ----------------------------------------------------------------------
> This message, and any attachments, is for the intended...{{dropped:13}}

______________________________________________
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