In KDB, how do I sum the previous 3 numbers in a list?

Viewed 58

Say I have a list of numbers:

j: (til 40)*9

0 9 18 27 36 45 54 63 72 81 90 99 108 117 126 135 144 153 162 171 180 189 198 207 216 225 234 243 252 261 270 279 288 297 306 315 324 333 342 351

What's the most elegant way to get the sum of the previous 3 (or n) numbers in the list? (Ideally considering large RAM constrained lists).

1 Answers

Does this work?

q)3 msum j
0 9 27 54 81 108 135 162 189 216 243 270 297 324 351 378 405 432 459 486 513 ..
Related