Qu

insert_column

Builtin index · Collections & strings

result = insert_column(t, name, values, [pos=])

Input: t, name, values, pos · Output: result

What it is

t is a Table; name is a Str; values is a numeric Vec/List of Str (or a scalar to broadcast) the same length as t's rows; optional named pos (number, default: append at the end) sets the column's position.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = insert_column(t, name, values, [pos=])
t Tablet is a Table.
name Strname is a Str.
values Vec, List, Str, or scalarvalues is a numeric Vec/List of Str (or a scalar to broadcast) the same length as t's rows.
pos number, optionaloptional named pos (number, default: append at the end) sets the column's position.
result Table
Returns a NEW Table; the original is untouched.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

runs = table(
    channel  = [1, 2, 3],
    baseline = [0.412, 0.508, 0.377],
    treated  = [0.240, 0.301, 0.219]
)
runs = insert_column(runs, "reduction", 1 - runs.treated / runs.baseline)
print(runs)
output
channel  baseline  treated  reduction
-------  --------  -------  ---------
      1     0.412     0.24   0.417476
      2     0.508    0.301    0.40748
      3     0.377    0.219   0.419098

from from-zero

How it works

insert_column(t, "name", values, [pos=]) (§ table row index, 2026-08-26) — a new Table with a new column inserted at pos (default: appended). values is a Vec for a numeric column or a Value::List of strings for a text column (the same list-of-strings shape column_names_arg/drop's tuple form already accepts elsewhere), matching the just-fixed df.colname text-column read shape (Value::List of Value::Str) on the way back out.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.