replaceColumn!

Syntax

replaceColumn!(table, colName, newCol)

Arguments

table is a non-shared in-memory table.

colName a string indicating a column name.

newCol a vector with the same number elements as the number of rows of table.

Details

Replace a table column with the specified vector. The data type of the new column is the same as the data type of the specified vector. The original column name is not changed.

To update column’s value without changing its data type, we can use both replaceColumn! and SQL statement update. Only replaceColumn!, however, can change a column’s data type.

Examples

$ 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

comment

timestamp

SECOND

10

sym

STRING

18

qty

INT

4

price

DOUBLE

16

To change the data type of column “sym” to SYMBOL:

$ syms=symbol(exec sym from t)
$ replaceColumn!(t,`sym,syms);
$ schema(t).colDefs;

name

typeString

typeInt

comment

timestamp

SECOND

10

sym

SYMBOL

17

qty

INT

4

price

DOUBLE

16