KDB Select average of List data type for each row

Viewed 109

Is there anyway in KDB to get the average of each row which has list data type ? E.g. I have table with column ID and Size :

| ID | size      |
|----|-----------|
| 1  | [1,3]     |
| 2  | [3,3,3]   |
| 3  | [4,2,4,2] |

In select , I want ID and avg of size :

| ID | avg |
|----|-----|
| 1  | 2   |
| 2  | 3   |
| 3  | 3   |
1 Answers
q)t:([]id:1 2 3;size:(1 3;3 3 3;4 2 4 2))
q)t
id size
----------
1  1 3
2  3 3 3
3  4 2 4 2
q)select id,avg each size from t
id size
-------
1  2
2  3
3  3
Related