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.

更多信息

  • 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:
  • constequivalent 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]. »

范例

打开所有单元关闭所有单元

基本范例  (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)

Insert a constant column:

Insert a vector column:

Insert a typed column:

Remove an existing column:

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:

Insert a column with a standard key:

Insert it matching the depth of the extended keys:

Input Data  (1)

Append a column to a Tabular object:

Placement of Columns  (3)

Insert a column before the first one:

Insert it after the first column:

Replace an existing column:

Add multiple columns at the same time:

Applications  (4)

Take a Tabular object of numbers:

Create a vector from the column "obs" that has zero mean and unit standard deviation:

Use InsertColumns to add it to the original tabular object:

Take a Tabular object containing medical data:

Check the column types:

Note that type for some columns is not numeric, despite the columns containing numbers:

Check for numeric inputs:

It is likely the data in these two columns cannot be trusted and needs to be marked to indicate that. Use InsertColumns to convert all the column entries to Missing:

Take a Tabular object of financial time series data:

Fit an autoregressive time series model to the data:

Simulate the values:

Add the simulation column to the data:

Visualize the data and the simulation:

Take a Tabular object with monthly data given in columns:

Insert empty string columns to serve as visual dividers:

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 several columns:

Append the same columns of the original Tabular object:

This is effectively equivalent to a transposition of the original data:

Wolfram Research (2025),InsertColumns,Wolfram 语言函数,https://reference.wolfram.com/language/ref/InsertColumns.html.

文本

Wolfram Research (2025),InsertColumns,Wolfram 语言函数,https://reference.wolfram.com/language/ref/InsertColumns.html.

CMS

Wolfram 语言. 2025. "InsertColumns." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/InsertColumns.html.

APA

Wolfram 语言. (2025). InsertColumns. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/InsertColumns.html 年

BibTeX

@misc{reference.wolfram_2025_insertcolumns, author="Wolfram Research", title="{InsertColumns}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/InsertColumns.html}", note=[Accessed: 15-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_insertcolumns, organization={Wolfram Research}, title={InsertColumns}, year={2025}, url={https://reference.wolfram.com/language/ref/InsertColumns.html}, note=[Accessed: 15-January-2025 ]}