替换kdb列中的前n个条目 [英] Replace first n entries in a column in kdb

查看:53
本文介绍了替换kdb列中的前n个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何替换表前n列中的值?即mycol:(1 2 3 4)到mycol:(a a 3 4)预先谢谢你!

How can I replace the values in the first n columns of my table? i.e, mycol:(1 2 3 4) to mycol: (a a 3 4) Thank you in advance!

推荐答案

如果是mycol中要更新的值,则它们必须与现有值具有相同的类型.见下文.

If it's the values within mycol that you want updated then they will need to be of the same type as the existing values. See below.

q)t:([]mycol:`$string 1+til 4;mycol2:til 4)
q)update mycol:`a from t where i<2
mycol mycol2
------------
a     0
a     1
3     2
4     3

解决此问题的一种方法是 enlist mycol,该方法可以进行任何类型的更新.

One way around this though is to enlist mycol, that way updates of any type can be made.

q)t:([]mycol:1+til 4;mycol2:til 4)
q)update mycol:`a from(update enlist each mycol from t)where i<2
mycol mycol2
------------
`a    0
`a    1
,3    2
,4    3
q)meta update mycol:`a from(update enlist each mycol from t)where i<2
c     | t f a
------| -----
mycol |
mycol2| j

不清楚您要更改列名还是更改列值.如果是列名,则可以使用 xcol .

It's unclear from your question whether you want the column names or the column values changed. If it's the column names, you can use xcol.

q)(2#`a)xcol([]w:3#til 3;x:3#.Q.a;y:`;z:0N)
a a y z
-------
0 a
1 b
2 c

这篇关于替换kdb列中的前n个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆