kdb-如何将十六进制颜色代码生成为字符串或符号
我想在内存表上创建一列,该列根据人名(另一列)生成颜色十六进制代码。一个快速的谷歌并没有给出太多,所以想知道是否可以在这里给出任何指示。例如
update colour: <some code and use username col as input> from table
回答
在 kdb+ 中,您可以通过update语句在列上运行函数,但根据函数是否矢量化而略有不同。如果矢量化:
update colour:{<some code>}[username] from table
update colour:someFunction[username] from table
如果未矢量化,则需要像each'这样的迭代器
update colour:{<some code>}'[username] from table
update colour:someFunction'[username] from table
此函数将从字符串的前 3 个字符生成十六进制代码。
q)hex:{a:i-16*j:(i:`int$3#x)div 16;"0123456789ABCDEF"raze(j-16*j div 16),'a}
q)hex"Hello"
"48656C"
q)update colour:hex'[username] from table
- In that regard you question is quite vague. What attempts have you made to generate HEX codes so far? Under what rules should the conversion be made? Do you only need the first 3 characters of a string to do it? I've added a hex code generator function to my answer.