is there a better way to do this? Calculate change over the 4th or Nth previous cell?
d=.(1+(i.4)),(1.25+(i.4)) d %~ ((# d) {. _4 {. d) 1.25 1.125 1.08333 1.0625 0 0 0 0 Here's how it's done in R > d<-ts(c(1:4, c(1:4)+0.25)) > d/lag(d,k=-4) Time Series: Start = 5 End = 8 Frequency = 1 [1] 1.250000 1.125000 1.083333 1.062500 > The parameter isn't very intuitive: d %~ ((# d) {. _6 {. d) 3 2 0.416667 0.5625 2.6 1.88889 0 0 > ts(c(1:4, c(1:4)+0.25)) / lag(ts(1:4),k=-2) Time Series: Start = 3 End = 6 Frequency = 1 [1] 3.0000000 2.0000000 0.4166667 0.5625000 If this is the right way, I'd probably define a dyad, or if I knew better an conjunction(?) lag=: 4 : 'y %~ ((# y) {. (_1*( x -~ # y)) {. y)' 2 lag d 3 2 0.416667 0.5625 2.6 1.88889 0 0 I naively thought I could just replace %~ with u lag=: 2 : 'y u ((# y) {. (_1*( x -~ # y)) {. y)' 4 %~ lag d |syntax error | 4%~lag d ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm