[R] xts object translation

Joshua Ulrich josh.m.ulrich at gmail.com
Sun Apr 7 22:18:29 CEST 2013


Use lag.xts:

R> lag(x,-1)
                aaa    bbb     ccc    ddd
2001-01-02 181.1751 243.24 1689.10 267.15
2001-01-03 181.6126 242.09 1737.86 267.10
2001-01-04       NA     NA      NA     NA

Note that the sign of k is different for lag.xts than lag.zoo (and lag.default).

R> lag(as.zoo(x),-1)
                aaa    bbb    ccc    ddd
2001-01-03 179.7061 239.11 1712.6 271.10
2001-01-04 181.1751 243.24 1689.1 267.15

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

R/Finance 2013: Applied Finance with R  | www.RinFinance.com


On Sun, Apr 7, 2013 at 8:34 AM, Michela <freerisk3 at gmail.com> wrote:
> i have an xts object:
>
>                      aaa               bbb            ccc              ddd
> 2001-01-02     179.7061        239.11      1712.60         271.10
> 2001-01-03     181.1751        243.24      1689.10         267.15
> 2001-01-04     181.6126        242.09      1737.86         267.10
>
> i simply want translate upward all the values
> So values in first row are lost. All others traslate upward
>
> In my example, xts object should become:
>
>                      aaa              bbb           ccc             ddd
> 2001-01-02     181.1751      243.24     1689.10        267.15
> 2001-01-03     181.6126      242.09     1737.86        267.10
> 2001-01-04     NA               NA           NA               NA
>
> Any idea how to do this upward translation?
>
> thanks
>
> ______________________________________________
> 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