Weighted deviation of list columns in kdb

How can I calculate a weighted average column from two other columns that have multiple entries per row in kdb?

For example, given the following table:

T:([]sym:`a`b`c;size:(2 8;5 2 10;3 7);price:(1 2;1 1 10;2 4))

I would like to add a column (1.8 6.29 3.4)to the table.

+4
source share
1 answer

You can use each-both adverb to apply wavg to each nested list in your table, for example

q)update x:wavg'[size;price] from T
sym size   price  x
--------------------------
a   2 8    1 2    1.8
b   5 2 10 1 1 10 6.294118
c   3 7    2 4    3.4
+1
source

Source: https://habr.com/ru/post/1689329/


All Articles