[R] Plot two zoo object with different indexes

2010-11-23 Thread Manta

Dear R community, I have the following two zoo objects:

MONTHLY CPI

 plot(z)
 par(usr)
[1] 1977.76333 2011.15333   70.39856  227.03744
 z=zooreg(cpius$Value,as.yearmon(1979-11),frequency=12)
 str(z)
‘zooreg’ series from Nov 1979 to Oct 2010
  Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ...
  Index: Class 'yearmon'  num [1:372] 1980 1980 1980 1980 1980 ...
  Frequency: 12 

AND A DAILY SERIES IN THE SAME RANGE

 plot(y)
 par(usr)
[1]  3233.8 15362.270.42363   226.38559
 str(y)
‘zoo’ series from 1980-02-01 to 2010-10-31
  Data: num [1:11231] 76.2 76.2 76.3 76.3 76.3 ...
  Index: Class 'Date'  num [1:11231] 3683 3684 3685 3686 3687 ...

Now, due to a different index (and a different usr parameter for the
graphic) I am not able to plot the two series together. How shall I do?

Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3055890.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Plot two zoo object with different indexes

2010-11-23 Thread Gabor Grothendieck
On Tue, Nov 23, 2010 at 12:53 PM, Manta mantin...@libero.it wrote:

 Dear R community, I have the following two zoo objects:

 MONTHLY CPI

 plot(z)
 par(usr)
 [1] 1977.76333 2011.15333   70.39856  227.03744
 z=zooreg(cpius$Value,as.yearmon(1979-11),frequency=12)
 str(z)
 ‘zooreg’ series from Nov 1979 to Oct 2010
  Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ...
  Index: Class 'yearmon'  num [1:372] 1980 1980 1980 1980 1980 ...
  Frequency: 12

 AND A DAILY SERIES IN THE SAME RANGE

 plot(y)
 par(usr)
 [1]  3233.8 15362.2    70.42363   226.38559
 str(y)
 ‘zoo’ series from 1980-02-01 to 2010-10-31
  Data: num [1:11231] 76.2 76.2 76.3 76.3 76.3 ...
  Index: Class 'Date'  num [1:11231] 3683 3684 3685 3686 3687 ...

 Now, due to a different index (and a different usr parameter for the
 graphic) I am not able to plot the two series together. How shall I do?


Try this:

library(zoo)
z1 - zooreg(1:20, start = as.yearmon(2000-01), freq = 12)
z2 - zoo(1:600, as.Date(2000-01-01) + 0:599)
m - merge(day = aggregate(z1, as.Date, identity), month = z2)
plot(na.approx(m))


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.


Re: [R] Plot two zoo object with different indexes

2010-11-23 Thread Manta

Thanks as always Gabor.

What I was looking for was to plot the daily series on the same graph of the
monthly using the command 'lines'. That is why I wanted to change the index
of one of the two, as it seems the reason why at the moment it is not
working!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3055936.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Plot two zoo object with different indexes

2010-11-23 Thread Gabor Grothendieck
On Tue, Nov 23, 2010 at 1:11 PM, Manta mantin...@libero.it wrote:

 Thanks as always Gabor.

 What I was looking for was to plot the daily series on the same graph of the
 monthly using the command 'lines'. That is why I wanted to change the index
 of one of the two, as it seems the reason why at the moment it is not
 working!

plot(na.approx(m), screen = 1)

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.


Re: [R] Plot two zoo object with different indexes

2010-11-23 Thread Manta

Ok this helps definitely! But I still would like to know

1. How to change from one index to another within a 'zoo' object
2. How to import using as index 'Date' a monthly series (code below). The
series in the US CPI from November 1979 to October 2010.

z - zoo(cpius$Value, as.Date(1979-11-30)+0:372)
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3056215.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Plot two zoo object with different indexes

2010-11-23 Thread Gabor Grothendieck
On Tue, Nov 23, 2010 at 3:58 PM, Manta mantin...@libero.it wrote:

 Ok this helps definitely! But I still would like to know

 1. How to change from one index to another within a 'zoo' object

Using

   z - zooreg(1:10, start = as.yearmon(2000-01), freq = 12)

Try

   aggregate(z, as.Date, identity)

or

   time(z) - as.Date(time(z))

Note that an example of the first approach was already shown in the
earlier answer.

 2. How to import using as index 'Date' a monthly series (code below). The
 series in the US CPI from November 1979 to October 2010.

 z - zoo(cpius$Value, as.Date(1979-11-30)+0:372)

Assuming the question is how to turn this daily series into a monthly series:

   aggregate(z, as.yearmon, function(x) tail(x, 1))

Suggest you carefully review ?aggregate.zoo

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.


Re: [R] Plot two zoo object with different indexes

2010-11-23 Thread Manta


Gabor Grothendieck wrote:
 
 2. How to import using as index 'Date' a monthly series (code below). The
 series in the US CPI from November 1979 to October 2010.

 z - zoo(cpius$Value, as.Date(1979-11-30)+0:372)
 
 Assuming the question is how to turn this daily series into a monthly
 series:
 
 

No, I have a monthly series and I want to create a zoo object indexed by
date and not by class yearmon or by a number (i.e., I would like to avoid
this two structures when importing monthly data and to have as index the
class date)

 z=zooreg(cpius$Value,as.yearmon(1978-11),frequency=12)
 str(z)
‘zooreg’ series from Nov 1978 to Oct 2009
  Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ...
  Index: Class 'yearmon'  num [1:372] 1979 1979 1979 1979 1979 ...
  Frequency: 12 
 z=zooreg(cpius$Value,start=c(1978,11),frequency=12)
 str(z)
‘zooreg’ series from 1978.833 to 2009.75
  Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ...
  Index:  num [1:372] 1979 1979 1979 1979 1979 ...
  Frequency: 12 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3056295.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Plot two zoo object with different indexes

2010-11-23 Thread Gabor Grothendieck
On Tue, Nov 23, 2010 at 4:41 PM, Manta mantin...@libero.it wrote:


 Gabor Grothendieck wrote:

 2. How to import using as index 'Date' a monthly series (code below). The
 series in the US CPI from November 1979 to October 2010.

 z - zoo(cpius$Value, as.Date(1979-11-30)+0:372)

 Assuming the question is how to turn this daily series into a monthly
 series:



 No, I have a monthly series and I want to create a zoo object indexed by
 date and not by class yearmon or by a number (i.e., I would like to avoid
 this two structures when importing monthly data and to have as index the
 class date)

 z=zooreg(cpius$Value,as.yearmon(1978-11),frequency=12)
 str(z)
 ‘zooreg’ series from Nov 1978 to Oct 2009
  Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ...
  Index: Class 'yearmon'  num [1:372] 1979 1979 1979 1979 1979 ...
  Frequency: 12
 z=zooreg(cpius$Value,start=c(1978,11),frequency=12)
 str(z)
 ‘zooreg’ series from 1978.833 to 2009.75
  Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ...
  Index:  num [1:372] 1979 1979 1979 1979 1979 ...
  Frequency: 12

How to convert a monthly series to a daily series has already been
illustrated in multiple ways in this thread.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.


Re: [R] Plot two zoo object with different indexes

2010-11-23 Thread Manta


Gabor Grothendieck wrote:
 
 How to convert a monthly series to a daily series has already been
 illustrated in multiple ways in this thread.
 

Fair enough. However, my last question was different. I simply want to know
if there is a simple neat way to import a monthly series as a zoo object
indexed by date without applying other function after the import (as in the
example, using aggregate)

Thanks

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3056327.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Plot two zoo object with different indexes

2010-11-23 Thread Gabor Grothendieck
On Tue, Nov 23, 2010 at 5:03 PM, Manta mantin...@libero.it wrote:


 Gabor Grothendieck wrote:

 How to convert a monthly series to a daily series has already been
 illustrated in multiple ways in this thread.


 Fair enough. However, my last question was different. I simply want to know
 if there is a simple neat way to import a monthly series as a zoo object
 indexed by date without applying other function after the import (as in the
 example, using aggregate)

 Thanks


If by import you mean reading it in from a file you can use the
read.zoo FUN= argument to manipulate the time index as you read it in
(and if you want to aggregate or split it at the same time there are
aggregate= and split= arguments as well).  See ?read.zoo

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@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.