[R] From daily series to monthly and viceversa

manta mantino84 at libero.it
Wed Apr 15 23:15:04 CEST 2009


Ok, thanks for the quick reply.
I was not able to use the first command, but reading the quick reference
helped me.
Here's what I did.

> cambio<-read.zoo("C:\\Users\\Manta\\Desktop\\useuro.txt", format =
> "%d/%m/%Y", dec = ",",header=T)
> cambio #this is what i get
1996-01-01 1996-01-02 1996-01-03 1996-01-04 1996-01-05 1996-01-08 1996-01-09
1996-01-10 1996-01-11 1996-01-12 1996-01-15 
   1.33139    1.33244    1.32790    1.31406    1.32811    1.32665    1.32469   
1.32842    1.32902    1.32680    1.32279

Then, using

> mcambio <- aggregate(cambio, as.yearmon, tail, 1) 
> mcambio
gen 1996 feb 1996 mar 1996 apr 1996 mag 1996 giu 1996 lug 1996 ago 1996 set
1996 ott 1996 nov 1996 dic 1996 gen 1997 
 1.28836  1.30718  1.30173  1.26778  1.27209  1.27933  1.31271  1.31042 
1.27980  1.28972  1.27267  1.27112  1.19681

But this is not what I wanted, because for example the january observation
is not the mean of the month of january, it is simply the last observation
of january. What I need is the mean of the month to be my monthly
observation. Also, the series has some missing data (exchange rates are not
traded every day) and every month could have different # of observation, is
this going to be a problem?

Thanks, Marco


Gabor Grothendieck wrote:
> 
> Try this:
> 
>> Lines <- "31/12/1993      1,12509
> + 03/01/1994      1,12509
> + 04/01/1994      1,12558
> + 05/01/1994      1,1258
> + 06/01/1994      1,12596
> + 07/01/1994      1,12753
> + 10/01/1994      1,1273
> + 11/01/1994      1,12416
> + 12/01/1994      1,1275"
>> library(zoo)
>> z <- read.zoo(textConnection(Lines), format = "%d/%m/%Y", dec = ",")
>> zm <- aggregate(z, as.yearmon, tail, 1); zm
> Warning message:
> closing unused connection 3 (Lines)
> Dec 1993 Jan 1994
>  1.12509  1.12750
> 
> and read ?read.zoo, ?aggregate.zoo and the three zoo vignettes
> vignette(package = "zoo") # lists their names
> vignette("zoo") # displays first one
> 
> On Wed, Apr 15, 2009 at 2:26 PM, manta <mantino84 at libero.it> wrote:
>>
>> I have the following daily exchange rate series  (from january 1st 1996
>> to
>> december 31st 2008) and I want to obtain them monthly series from it.
>> I've
>> read about the 'zoo' library but I'm not getting it how to do it. These
>> are
>> the data (left column day-month-year, right column the index)
>>
>> 31/12/1993      1,12509
>> 03/01/1994      1,12509
>> 04/01/1994      1,12558
>> 05/01/1994      1,1258
>> 06/01/1994      1,12596
>> 07/01/1994      1,12753
>> 10/01/1994      1,1273
>> 11/01/1994      1,12416
>> 12/01/1994      1,1275
>>
>> Also, I have monthly CPI data and I want to interpolate using the
>> reference
>> CPI formula in order to obtain the daily series. The time window is the
>> same
>> (January 1996, December 2008).
>> Thanks in advance for your help.
>>
>> --
>> View this message in context:
>> http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23064454.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23067288.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list