cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
nikles
Level VI

Possible to rename all columns in a table from a list?

Hi.  I'm wondering if there's a way to rename all columns in a table from a list without using a For loop.  I have tables with ~10k columns and using a For loop takes a lot longer than I'd like.  

 

Details:

JMP Pro 16.2.0

Mac OS Big Sur 11.6.6

 

I've looked into the Recode Column Names... feature (Cols > Column Names > Recode Column Names...).  In the dialog that appears, I can then select the red down triangle and Advanced > Apply Mapping from Table....   Assuming I have a table with the original and new column names, this appears to work well.  However, there doesn't appear to be a way to script this though.  

 

I've also tried transposing the table, adding a new column with the new column names, and then re-transposing using the new column as the labels.  This works too, but is too slow for tables my size.

 

Does anyone know of another clever way to do this without using a For loop?

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Possible to rename all columns in a table from a list?

I feel like renaming columns with looping shouldn't really take that long.

Names Default To Here(1);

dt = New Table("test", invisible);

For(i = 1, i <= 10000, i++,
	dt << New Column(Char(i*10), values(1::10000))
);

col_names = As List((1::10000)`);
wait(1);

start = HP Time();
For Each({col_name, idx}, col_names,
	Column(dt, idx) << Set Name(char(col_name));
);
Show((HP Time() - start) / 1e6);
-Jarmo

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Possible to rename all columns in a table from a list?

One interactive way to do this, is to copy all of your new column names into the paste buffer.

txnelson_0-1654545912292.png

Then select all columns from the Columns Panel in your data table.  I suggest that you use CNTL/a to select them all

txnelson_1-1654546051337.png

And then use CNTL/v to paste from the paste buffer to the column names

txnelson_2-1654546150351.png

 

Jim
jthi
Super User

Re: Possible to rename all columns in a table from a list?

I feel like renaming columns with looping shouldn't really take that long.

Names Default To Here(1);

dt = New Table("test", invisible);

For(i = 1, i <= 10000, i++,
	dt << New Column(Char(i*10), values(1::10000))
);

col_names = As List((1::10000)`);
wait(1);

start = HP Time();
For Each({col_name, idx}, col_names,
	Column(dt, idx) << Set Name(char(col_name));
);
Show((HP Time() - start) / 1e6);
-Jarmo
nikles
Level VI

Re: Possible to rename all columns in a table from a list?

Thanks jthi.  Yeah I have to admit, using a For loop is a lot faster than I remember.  I tried it a long time ago and recall thinking it was too slow.  Should've tried it again before asking...