didn't look totally at what you are trying to do, but (1+(i.4)),(1.25+(i.4)) 1 2 3 4 1.25 2.25 3.25 4.25
5 ({: - {.)\ 1 2 3 4 1.25 2.25 3.25 4.25 0.25 0.25 0.25 0.25 \ used dyadically using overlapping groups of length 5 in this case. ----- Original Message ----- From: Joe Bogner <joebog...@gmail.com> To: programm...@jsoftware.com Cc: Sent: Friday, February 21, 2014 5:58:36 PM Subject: [Jprogramming] simple time series (lag) 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm