rename!
Syntax
rename!(X, Y, [Z])
Arguments
X is a vector/matrix/in-memory table.
-
When X is a vector, Y is a string/symbol.
-
When X is a matrix, if Z is not specified, Y is the column names; if Z is specified, Y is the row names and Z is the column names. Column names and row names need to be of same length as the number of columns and rows in X. Y and Z could be data of any types.
-
When X is an in-memory table, Y and Z is a string scalar or vector. If Z is not specified, Y is new column names starting from the first column on the left; if Z is specified, Y is the old column names and Z is the corresponding new column names. Users should make sure the number of new or old column names be less than or equal to the total number of columns in the table.
Details
For a vector, assign a new name.
For a matrix, add or change columns names or row names.
For a table, rename the columns.
Examples
k=3 6 9;
k.rename!(`rk);
// output
[3,6,9]
// one way to check name is to use function stat to get the descriptive statistics of data
>stat k;
Median->6
Avg->6
Min->3
Stdev->3
Count->3
Size->3
Name->rk // the new name for k
Max->9
m1=1..9$3:3;
m1
#0 | #1 | #2 |
---|---|---|
1 | 4 | 7 |
2 | 5 | 8 |
3 | 6 | 9 |
m1.rename!(`col1`col2`col3);
col1 | col2 | col3 |
---|---|---|
1 | 4 | 7 |
2 | 5 | 8 |
3 | 6 | 9 |
m1.rename!(1 2 3, `c1`c2`c3);
c1 | c2 | c3 | |
---|---|---|---|
1 | 1 | 4 | 7 |
2 | 2 | 5 | 8 |
3 | 3 | 6 | 9 |
// note the new matrix uses the name of k as its column name.
m1 join k;
c1 | c2 | c3 | rk | |
---|---|---|---|---|
1 | 1 | 4 | 7 | 3 |
2 | 2 | 5 | 8 | 6 |
3 | 3 | 6 | 9 | 9 |
t1=table(1..3 as x, 4..6 as y, 7..9 as z);
t1
x | y | z |
---|---|---|
1 | 4 | 7 |
2 | 5 | 8 |
3 | 6 | 9 |
t1.rename!(`a`b);
a | b | z |
---|---|---|
1 | 4 | 7 |
2 | 5 | 8 |
3 | 6 | 9 |
t1.rename!(`aa`bb`cc);
aa | bb | cc |
---|---|---|
1 | 4 | 7 |
2 | 5 | 8 |
3 | 6 | 9 |
t1.rename!(`bb`cc, `y`z);
aa | y | z |
---|---|---|
1 | 4 | 7 |
2 | 5 | 8 |
3 | 6 | 9 |
t1=table(1..3 as x, 4..6 as y, 7..9 as z, k);
t1
// note the table uses the name of k as its column name.
x | y | z | rk |
---|---|---|---|
1 | 4 | 7 | 3 |
2 | 5 | 8 | 6 |
3 | 6 | 9 | 9 |