Closed nathanvy closed 1 year ago
For some of these things it's easier to convert to an array and then use array-operations. There's an example in that document on displaced arrays implementing sliding windows:
(defparameter stocks (aops:linspace 1 100 100))
(loop for i from 0 to (- (length stocks) 20)
do (format t "~A~%" (aops:displace stocks 20 i)))
;#(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
;#(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21)
;#(3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22)
that could be a foundation for other windowing functions.
Thanks Steve, I'll use that.
Does data-frame implement a facility for easily computing windowing functions? For example in python/pandas we can trivially calculate a rolling moving average with the baked-in data frame API. Pandas contains a rich set of common window functions and also lets you supply your own function via lambda.
What's nice is the library handles bounds-checking and whatnot automatically in a convenient and ergonomic manner.
Is there a way to do this with data-frame? If there's no built-in, what's the "canonical" way to iterate over two columns in lockstep, using one to compute the values of the other? I'm visualizing a pretty messy LOOP construct and hoping there's an easier way.