Calculating weighted averages is easy in kdb thanks to the wavg function. How can I calculate the delay between two consecutive rows of times and use these values ββas a parameter of weights for wavg?
Sort of:
`date`ts xasc select date,ts,mytw:(next ts - ts) wavg mycolumnval from pmd where date=2013.05.22
next gives the next column of rows in the query, but I can't figure out how to subtract the two ts values ββand use them in wavg .
UPDATE The solution was to use parentheses: ((next ts) - ts) . Please note that I cannot use deltas[ts] . This will result in different weights:
08:15:19.811 00:00:00.000 08:15:19.811 00:00:00.001 08:15:19.812 00:00:00.014 08:15:19.826 00:00:07.305 08:15:27.131 NULL
This is deltas[ts] :
08:15:19.811 08:15:19.811 08:15:19.811 00:00:00.000 08:15:19.812 00:00:00.001 08:15:19.826 00:00:00.014 08:15:27.131 00:00:07.305
source share