If I have a data table set up as below
| Col1 | Col2 | Col3 | Col4 |
| 1 | a | e | 20 |
| 2 | b | f | 21 |
| 3 | c | g | 22 |
and a list of strings for new column names
NewCols = { "Data1", "Data2", "Data3", "Data4"}
How can I write a script to rename the columns of the data table all once using the list New Cols such that it results in the following data table?
| Data1 | Data2 | Data3 | Data4 |
| 1 | a | e | 20 |
| 2 | b | f | 21 |
| 3 | c | g | 22 |
Hi @user8421,
It may not be applicable to you yet, but in JMP 16 (and later) you can use an improved For Each() jsl command to do this quickly:
dt = Current Data Table();
NewCols = { "Data1", "Data2", "Data3", "Data4"}
For Each( {value, index}, NewCols, Column( dt, index ) << set name( value ) );
I hope this helps!
@julian
I am not aware of a single statement that will change the column names. Below is the method that I use in such situations.
Names Default To Here( 1 );
dt = New Table( "Example",
Add Rows( 3 ),
New Column( "Col1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [1, 2, 3] )
),
New Column( "Col2", Character( 16 ), "Nominal", Set Values( {"a", "b", "c"} ) ),
New Column( "Col3", Character( 16 ), "Nominal", Set Values( {"e", "f", "g"} ) ),
New Column( "Col4",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [20, 21, 22] )
)
);
NewCols = {"Data1", "Data2", "Data3", "Data4"};
For( i = 1, i <= N Items( NewCols ), i++,
Column( dt, i ) << set name( NewCols[i] )
);