[R] fraction with timelag

Patrick Hausmann patrick.hausmann at uni-bremen.de
Thu Mar 24 12:31:03 CET 2011


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!
Patrick



More information about the R-help mailing list