KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ select avg (ignore null) Re: select avg (ignore null)

  • davidcrossey

    Member
    June 29, 2022 at 12:00 am

    Hi powerpeanuts,

    As per this note avg does ignore nulls for a single vector, so you could apply the average to each pair of values from each column as follows:

    q)t:([]c1:`a`b`c;c2:1 0N 2;c3:5 3 5) 
    q)update c4:avg each flip (c2;c3) from t 
    c1 c2 c3 c4 
    ------------ 
    a  1  5  3 
    b     3  3 
    c  2  5  3.5

    Hope this helps