[R] fraction with timelag

From: Patrick Hausmann <patrick.hausmann_at_uni-bremen.de>
Date: Thu, 24 Mar 2011 12:31:03 +0100

Dear r-help,

I'm having this DF

df <- data.frame(id = 1:6,

                  xout = c(1234, 2134, 234, 456, 324, 345),
                  xin= c(NA, 34,67,87,34, NA))

and would like to calculate the fraction (xin_t / xout_t-1) The result should be:
# NA, 2.76, 3.14, 37.18, 7.46, NA

I am sure there is a solution using zoo... but I don't know how...

Thanks for any help!

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 Thu 24 Mar 2011 - 11:35:01 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 Thu 24 Mar 2011 - 12:20:23 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