d=: (1+(i.4)),(1.25+(i.4))

   (4 }. d) % _4 }. d


Or, abstracting that.


   4 (}. % (-@[ }. ])) d

1.25 1.125 1.08333 1.0625


Here's how I think I would define lag:


lag=: 1 :0

  }. u -@[ }. ]

)


Or, if you prefer:


lag=: 1 :0

:

  (x }. y) u (-x) }. y

)


That said, if shift works for you that's even better.


Thanks,


-- 

Raul





On Fri, Feb 21, 2014 at 5:58 PM, Joe Bogner <joebog...@gmail.com> wrote:

> 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

Reply via email to