How to replace first n entries in a column with 0N

57 views
Skip to first unread message

Emily Wilson

unread,
Apr 6, 2021, 8:51:51 AM4/6/21
to Kdb+ Personal Developers
Hi, 
I am running a calculation and I want to replace my first n entries in the row with empty value. How should I do that?
i.e,                  mycol                                     mycol
                --------------------        to              ---------------------
                          a                                              0N
                          b                                              0N
                          c                                               c
                          d                                               d
Thank you so much for your help!
Emily
                -

András Dőtsch

unread,
Apr 6, 2021, 10:15:48 AM4/6/21
to personal...@googlegroups.com
update mycol:0N from `mytable where i<n

Andras

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbpl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/personal-kdbplus/7add40b7-2197-4ef5-879c-cd1ac94d53a4n%40googlegroups.com.

Nick Psaris

unread,
Apr 10, 2021, 3:13:43 PM4/10/21
to personal...@googlegroups.com
if you ever need to replace the first two elements 'by sym', for example, depending on 'i' won't help.

one alternative is to explicitly drop the first two elements and append two with null values:
q)t:([]mycol:`a`b`c`d)
q)update (``,2_) mycol from t

careful with this one, because the ',' append operator will be parsed by q-sql if it is not surrounded by parenthesis

another option is to use the '@' amend operator and replace the first two elements with null values
q)update @[;0 1;:;`] mycol from t




Emily Wilson

unread,
Apr 11, 2021, 10:46:24 AM4/11/21
to Kdb+ Personal Developers
Thank you so much for your help, Nick!
Reply all
Reply to author
Forward
0 new messages