Re: [R] Pointwise division of two zoo objects?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 15 Mar 2011 09:27:41 -0400

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

______________________________________________
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.
Received on Tue 15 Mar 2011 - 13:46:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 15 Mar 2011 - 13:50:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive