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

瀏覽次數:57 次
跳到第一則未讀訊息

Emily Wilson

未讀,
2021年4月6日 上午8:51:512021/4/6
收件者: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

未讀,
2021年4月6日 上午10:15:482021/4/6
收件者: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

未讀,
2021年4月10日 下午3:13:432021/4/10
收件者: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

未讀,
2021年4月11日 上午10:46:242021/4/11
收件者:Kdb+ Personal Developers
Thank you so much for your help, Nick!
回覆所有人
回覆作者
轉寄
0 則新訊息