[R] Pointwise division of two zoo objects?

Gabor Grothendieck ggrothendieck at gmail.com
Tue Mar 15 14:27:41 CET 2011


On Mon, Mar 14, 2011 at 10:16 PM, Adam Gustafson <amg81 at uw.edu> wrote:
> Just trying to create returns from prices, and do something like:
>
> returns.z = tail(prices.z,-1)/head(prices.z,-1) - 1  # should be equivalent
> to returns = exp(diff(log(prices.z))) - 1
>
> Curiously, I get a zoo object back with zeros everywhere and also with the
> index having one fewer element than it should.
>
> Does anyone know how to pointwise divide zoo objects, and what exactly "/"
> is doing?
>

Try this:

     diff(x, arithmetic = FALSE) - 1

and see ?diff.zoo




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



More information about the R-help mailing list