[R] Embed function strips out date index
Manussawee Sukunta
msukunta at illinoisalumni.org
Wed Jun 30 23:28:28 CEST 2010
Sorry - I actually thought about it after I'd sent out the first message.
When I did
>attributes(series)
I saw that series$class is 'xts' 'zoo'.
I just want to keep some sort of indexing so that I can keep track of
what is going on... a sanity check. My database can get quite large.
I will try
rownames(series.d) <- rownames(series)
per Peter's suggestion in the meanwhile.
May be something will click in my head later...
Thank you again,
Manussawee
On Wed, Jun 30, 2010 at 3:54 PM, Jonathan Christensen
<dzhonatan at gmail.com> wrote:
> Manussawee,
>
> What type of object is series? We could help you better if we could
> reproduce exactly what you are trying to do, which requires more information
> (you made a good start by including data and code, though).
>
> The output of diff is a vector (time series, ...) with length one less than
> the input. embed(..., 2) also returns an object with length one less than
> the input. This is why you noticed that series.d had a different length than
> series (shorter by exactly 2, I bet).
>
> You should be able to figure out what you want to do from there. Since I
> don't know how you want the dates to line up, I can't really help you
> anymore from here.
>
> Jonathan
>
>
> On Wed, Jun 30, 2010 at 2:32 PM, Manussawee Sukunta
> <msukunta at illinoisalumni.org> wrote:
>>
>> Hi,
>>
>> I'm having especially hard time today and couldn't find any
>> clue/answer through the internet. I hope you can help.
>>
>> I'm in a process of writing a script to estimate error correction
>> model, and I was following an example in Bernhard Pfaff's Analysis of
>> Integrated and Cointegrated Time Series with R. I have the following
>> price data:
>>
>> > head(series,15)
>> PX_SETTLE PX_SETTLE.1
>> 2009-01-02 4515.0 925.50
>> 2009-01-05 4540.5 927.50
>> 2009-01-06 4603.5 930.50
>> 2009-01-07 4470.5 905.25
>> 2009-01-08 4474.5 906.75
>> 2009-01-09 4430.5 885.50
>> 2009-01-12 4402.0 868.00
>> 2009-01-13 4343.5 868.50
>> 2009-01-14 4130.5 839.75
>> 2009-01-15 4070.5 839.25
>> 2009-01-16 4129.5 848.50
>> 2009-01-20 4032.0 806.00
>> 2009-01-21 4018.0 836.75
>> 2009-01-22 4011.0 825.50
>> 2009-01-23 3998.0 823.50
>>
>> Then I defined
>> series.d = embed(diff(series),dim=2)
>>
>> which resulted in
>> > head(series.d,15)
>> [,1] [,2] [,3] [,4]
>> [1,] 25.5 2.00 NA NA
>> [2,] 63.0 3.00 25.5 2.00
>> [3,] -133.0 -25.25 63.0 3.00
>> [4,] 4.0 1.50 -133.0 -25.25
>> [5,] -44.0 -21.25 4.0 1.50
>> [6,] -28.5 -17.50 -44.0 -21.25
>> [7,] -58.5 0.50 -28.5 -17.50
>> [8,] -213.0 -28.75 -58.5 0.50
>> [9,] -60.0 -0.50 -213.0 -28.75
>> [10,] 59.0 9.25 -60.0 -0.50
>> [11,] -97.5 -42.50 59.0 9.25
>> [12,] -14.0 30.75 -97.5 -42.50
>> [13,] -7.0 -11.25 -14.0 30.75
>> [14,] -13.0 -2.00 -7.0 -11.25
>> [15,] 169.0 7.25 -13.0 -2.00
>>
>> The new data series.d now has no date index. I'm not sure how to get
>> it back. I tried to xts --> order.by = index(series), but the vector
>> lengths are now not the same. I feel like the answer might be
>> obvious, but I just can't see it. Again, I tried searching various
>> forums and sites, but I couldn't find my answer. I feel like I'm just
>> going around a circle. I hope someone can help me and shed some light
>> on this problem.
>>
>> Thank you,
>> Manussawee
>>
>> ______________________________________________
>> 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.
>
>
--
Visit my blog at http://somthum.blogspot.com
More information about the R-help
mailing list