Replaces a column of a table.
REPLACECOL(series, newcol, colnum, inplace)
series |
- |
A multi-column series. |
||
newcol |
- |
A series, the new column to replace the existing column. |
||
colnum |
- |
Optional, an integer, the column number to replace.
|
||
inplace |
- |
Optional. An integer, the operate in-place flag:
|
A series or table.
W1: reshape(1..10, {3, 5, 2})
W2: replacecol(W1, 1..3)
W3: replacecol(W1, 1..3, 2)
W4: replacecol(W1, 1..3, 3)
W1 contains the table:
1 4 9
2 5 10
3 6
7
8
W2 contains the table:
1 4 9 1
2 5 10 2
3 6 3
7
8
W3 contains the table:
1 1 9
2 2 10
3 3
W4 contains the table:
1 4 1
2 5 2
3 6 3
7
8
W1: reshape(1..10, {3, 5, 2})
W2: replacecol(W1, ones(2, 2), 2)
W1 contains the table:
1 4 9
2 5 10
3 6
7
8
W2 contains the table:
1 1 1 9
2 1 1 10
3
a = ravel(1..9, 3);
b = ravel(1..9, 3);
a = replacecol(a, {100, 101, 102}, 2);
replacecol(b, {100, 101, 102}, 2, 1);
Initially:
a == {{1, 4, 7},
{2, 5, 8},
{3, 6, 9}}
b == {{1, 4, 7},
{2, 5, 8},
{3, 6, 9}}
After replacement:
a == {{1, 100, 5},
{2, 101, 5},
{3, 102, 5}}
b == {{1, 100, 5},
{2, 101, 5},
{3, 102, 5}}
A column 2 is replaced for both arrays. However, variable a is reassigned to an entirely new array object,
while the column is modified directly in the original array of variable
b (
By default, REPLACECOL does not modify
the original data and instead returns a new series. For very large arrays
where memory allocation is costly, enabling
As shown in the second example, if the new series contains multiple columns, all of the new columns replace the original column.
Columns can also be replaced by assigning a series to a column. For example:
a = ravel(1..16, 4);
a[.., 3] = 100..103;
a == {{1, 5, 100, 13},
{2, 6, 101, 14},
{3, 7, 102, 15},
{4, 8, 103, 16}}
See INSERTCOL to insert one or more columns into a table.