%/ 1.25 1 (4 : 'x+"0 1 i.y') 4
1.25 1.125 1.0833333 1.0625

for  a given array do

       %~/ ([\~-@-:@#)   (1+(i.4)),(1.25+(i.4))
1.25 1.125 1.0833333 1.0625


R.E. Boss

(Add your info to http://www.jsoftware.com/jwiki/Community/Demographics )


> -----Original Message-----
> From: programming-boun...@forums.jsoftware.com [mailto:programming-
> boun...@forums.jsoftware.com] On Behalf Of Joe Bogner
> Sent: vrijdag 21 februari 2014 23:59
> To: programm...@jsoftware.com
> 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

Reply via email to