如何在kdb中创建带符号的字符串/列表?

时间:2018-01-03 14:29:59

标签: kdb q-lang

我有一个包含一列字符串的表,我想创建一个带有字符串类型的新列,并在每个字符串项的前面创建`。我怎么做?  例如:

a
b
c

"\`a"
"\`b"
"\`c"

4 个答案:

答案 0 :(得分:4)

另一种解决方案(在这种情况下更快):

```{r, echo=FALSE}
library(rmarkdown) #used for syntax highlighting in this document
library(shiny)
```
#read in file of item ids from website and parse

```{r code, eval=FALSE}
url = "http://eve-files.com/chribba/typeid.txt"
df = read_fwf(url, fwf_empty(url), skip = 2)
colnames = read_table(url, n_max = 1)
names(df) = names(colnames)
```

答案 1 :(得分:3)

以下表为例:

q)show tab:([]a:("a";"b";"c"))
a
-
a
b
c

要获得一个带有反引号的新列,您需要在每行附加"`"

q)update b:("`",'a) from tab
a b
------
a "`a"
b "`b"
c "`c"

如果列由符号组成,则只需要首先将其转换为字符串:

q)tab2:([]a:`a`b`c)
q)update b:("`",'string a) from tab2
a b
------
a "`a"
b "`b"
c "`c"

答案 2 :(得分:1)

有时人们比SQL更熟悉SQL,当他们只需要处理向量时,就表格提出问题;并创建新列,其中所需的只是一个变量 - 或者作为参数传递的值。

a

当然,tab的{​​{1}}列只是向量"abc",所以

q)"`",'"abc"
"`a"
"`b"
"`c"

可能就是您所需要的一切。

请参阅:

答案 3 :(得分:0)

这是另一种方式: 从标签更新(“`”,/:a)