replaceColumn!
语法
replaceColumn!(table, colName, newCol)
参数
table 非共享内存表。
colName 字符串,表示列名。
newCol 长度与表的行数相同的向量。
详情
使用一个向量替换 table 中指定列。替换后,指定列的数据类型与向量的数据类型一致。
replaceColumn! 与 SQL 中的 update 语句的区别在于,前者可以修改列的值或数据类型,而后者只能修改列的值。
例子
$ sym = `C`MS`MS`MS`IBM`IBM`C`C`C
$ price= 49.6 29.46 29.52 30.02 174.97 175.23 50.76 50.32 51.29
$ qty = 2200 1900 2100 3200 6800 5400 1300 2500 8800
$ timestamp = [09:34:07,09:36:42,09:36:51,09:36:59,09:32:47,09:35:26,09:34:16,09:34:26,09:38:12]
$ t = table(timestamp, sym, qty, price)
$ schema(t).colDefs;
name |
typeString |
typeInt |
extra |
comment |
---|---|---|---|---|
timestamp |
SECOND |
10 |
||
sym |
STRING |
18 |
||
qty |
INT |
4 |
||
price |
DOUBLE |
16 |
把sym列的数据类型修改为SYMBOL类型:
$ syms=symbol(exec sym from t)
$ replaceColumn!(t,`sym,syms);
$ schema(t).colDefs;
name |
typeString |
typeInt |
extra |
comment |
---|---|---|---|---|
timestamp |
SECOND |
10 |
||
sym |
SYMBOL |
17 |
||
qty |
INT |
4 |
||
price |
DOUBLE |
16 |