cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Agustin
Level IV

Easy way of reordering columns

I have a script that reformats many files and performs some analysis producing a final summary table, however the order in which the calculations are done and new columns are added doesn't produce a very readable format.

I would like to pass the list of column names in the order I want them.

Is there a built - in way of doing this?

 

e.g. if I had a table with: Column 1, Column 2, Column 3, Column 4

 

I want to pass in the list {Column 2, Column 4, Column 1, Column 3} to the table and have the reorder the table columns to match.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Easy way of reordering columns

Here is the way I handle this.  By working backwards through the list, and moving each to the first position, the columns end up as you want them.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
myList = {"age", "weight", "height"};
For( i = N Items( myList ), i >= 1, i--,
	Eval( Parse( "dt << Move Selected Columns(" || myList[i] || ", To first )" ) )
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Easy way of reordering columns

Here is the way I handle this.  By working backwards through the list, and moving each to the first position, the columns end up as you want them.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
myList = {"age", "weight", "height"};
For( i = N Items( myList ), i >= 1, i--,
	Eval( Parse( "dt << Move Selected Columns(" || myList[i] || ", To first )" ) )
);
Jim
stan_koprowski
Community Manager Community Manager

Re: Easy way of reordering columns

Nice,  simple and clever solution @txnelson 

Agustin
Level IV

Re: Easy way of reordering columns

That's such an ingenious fix!