InsertColumns
InsertColumns[tab,{col1cval1,…}]
inserts the column cvali with name coli in the tabular object tab.
InsertColumns[cspec]
represents an operator form of InsertColumns that can be applied to a tabular object.
Details
- InsertColumns is typically used to build a Tabular object with additional columns.
- If the column coli already exists, it is replaced with the new column. Otherwise, the new column is added after the existing ones. »
- The inserted columns must have the same number of rows as the original tabular object.
- InsertColumns[tab,{acol,colcval}] adds a new column named col after the existing anchor column named acol, instead of appending it at the end. »
- For tabular data atab without column keys, InsertColumns[atab,{cval1,…,cvaln}] appends n new columns. »
- Possible column specifications cvali to be inserted in a tabular object of n rows include:
-
const equivalent to ConstantArray[const,n] » {v1,…,vn} vector of length n » TabularColumn[…] type-consistent vector of length n » - The syntax colNothing can be used to remove the existing column named col. »
- InsertColumns[cspec][tab] is equivalent to InsertColumns[tab,cspec]. »
Examples
open allclose allBasic Examples (2)
Insert a new column at the end:
Insert the new column after the first column:
Use operator form of InsertColumns:
Scope (11)
Columns (7)
Add multiple columns at the same time:
Columns can be inserted with their key wrapped in Key or ExtendedKey:
Extended keys can have different depths than in the original:
Take a Tabular object with extended keys:
Input Data (1)
Append a column to a Tabular object:
Properties & Relations (5)
Specifying different columns for the same new key will use the last specification:
An empty second argument represents insertion of zero columns:
Use TransformColumns to append a new column to a Tabular object:
Alternatively, first compute the column and then use InsertColumns to append it:
Take a Tabular object whose columns are years and months:
TransformColumns can add a new column by constructing a date for each row:
Alternatively, first construct the column of dates and then use InsertColumns to append it:
Append a column to an anonymous Tabular object:
The same result can be achieved by joining matrices at their second level with Join:
Append the same columns of the original Tabular object:
This is effectively equivalent to a transposition of the original data:
Text
Wolfram Research (2025), InsertColumns, Wolfram Language function, https://reference.wolfram.com/language/ref/InsertColumns.html.
CMS
Wolfram Language. 2025. "InsertColumns." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/InsertColumns.html.
APA
Wolfram Language. (2025). InsertColumns. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/InsertColumns.html