Class: Table
An immutable table of named, equally long columns. Built by toTable (which every Express function calls on its data) or fromCSV.
Example
ts
const t = toTable([
{ a: 1, b: 'x' },
{ a: 2, b: 'y' },
]);
t.names; // ['a', 'b']
t.column('a'); // [1, 2]
t.type('b'); // 'categorical'Constructors
Constructor
ts
new Table(columns): Table;Parameters
| Parameter | Type | Description |
|---|---|---|
columns | | Record<string, readonly unknown[]> | ReadonlyMap<string, readonly unknown[]> | Columns by name; they must all have the same length. |
Returns
Table
Throws
When columns differ in length.
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
length | readonly | number | Number of rows. |
names | readonly | readonly string[] | Column names, in order. |
Methods
column()
ts
column(name): readonly unknown[];The values of a column.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
readonly unknown[]
Throws
When there is no such column (the message lists the columns).
has()
ts
has(name): boolean;Whether the table has a column called name.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
boolean
toColumns()
ts
toColumns(): Record<string, readonly unknown[]>;The table as an object of columns (the arrays themselves, not copies).
Returns
Record<string, readonly unknown[]>
toRows()
ts
toRows(): Record<string, unknown>[];The table as row objects.
Returns
Record<string, unknown>[]
type()
ts
type(name): ColumnType;The inferred type of a column (see inferColumnType); computed once.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
withColumn()
ts
withColumn(name, values): Table;A new table with one more column (or a column replaced).
Parameters
| Parameter | Type |
|---|---|
name | string |
values | readonly unknown[] |
Returns
Table