table

Syntax

table(X, [X1], [X2], …..)

or

table(capacity:size, colNames, colTypes)

Arguments

For the first scenario: X, X1, X2 … can be vectors, matrices or tuples. Each vector, each matrix column and each tuple element must have the same length.

For the second scenario:

capacity is the amount of memory (in terms of the number of rows) allocated to the table. When the number of rows exceeds capacity, the system will first allocate memory of 1.2~2 times of capacity, copy the data to the new memory space, and release the original memory. For large tables, these steps may use significant amount of memory.

size is the initial size (in terms of the number of rows) of the table. If size=0, create an empty table.

colNames a string vector of column names.

colTypes is a string vector of data types. It can use either the reserved words for data types or corresponding strings.

Details

Create an in-memory table.

Examples

Examples of table(X, [X1], [X2], …..):

$ id=`XOM`GS`AAPL
$ x=102.1 33.4 73.6
$ table(id, x);

id

x

XOM

102.1

GS

33.4

AAPL

73.6

$ table(`XOM`GS`AAPL as id, 102.1 33.4 73.6 as x);

id

x

XOM

102.1

GS

33.4

AAPL

73.6

In the following example, table t is created from a vector x, a matrix y and a tuple z.

$ x=1..6
$ y=matrix(11..16, 17..22)
$ z=(101..106, 201..206)
$ t=table(x,y,z)
$ t.rename!(`x`y1`y2`z1`z2);

$ t;

x

y1

y2

z1

z2

1

11

17

101

201

2

12

18

102

202

3

13

19

103

203

4

14

20

104

204

5

15

21

105

205

6

16

22

106

206

Convert a matrix into a table:

$ m=matrix(1 2, 3 4, 5 6);
$ m;

#0

#1

#2

1

3

5

2

4

6

$ t=table(m).rename!(`a`b`x);
$ t;

a

b

x

1

3

5

2

4

6

Examples of table(capacity:size, colNames, colTypes):

$ table(100:5, `name`id`value, [STRING,INT,DOUBLE]);

name

id

value

0

0

0

0

0

0

0

0

0

0

$ table(100:5, `name`id`value, `STRING`INT`DOUBLE);

name

id

value

0

0

0

0

0

0

0

0

0

0

$ table(100:1, [`value], [DOUBLE]);

value

0