cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Jiaxiang
Level I

How to insert a column with specified column index with JMP script?

I met a problem when writting my JMP script, I want to add the new column with a formula Y/X but there are serveal colunms and I want to add the new colunm after specified column,

For example:

A Table like:

A    B    C    D

1    2     3    4

2    4     6    8

 

and I want to add a new column after B column(like below), but the B/A column will always after D when I use New Column function, and I cannot find a good function from the scripting index , how to insert a column to a specified column index?

 

<<New Column("B/A",formula(:B/:A));

 

A    B   B/A   C    D

1    2      2     3    4

2    4      2     6    8

 

 

 

 

 

 

 

 

 

1 REPLY 1
txnelson
Super User

Re: How to insert a column with specified column index with JMP script?

Use the 

<< Move Selected Columns()

message to move the new column to where you want it

Names Default To Here( 1 );
// Open Data Table: big class.jmp
// → Data Table( "big class" )
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// New column: Column 6
dt << New Column( "Column 6",
	Numeric,
	"Continuous",
	Format( "Best", 12 )
) << Move Selected Columns( {:Column 6}, after( :sex ) );

or

Names Default To Here( 1 );
// Open Data Table: big class.jmp
// → Data Table( "big class" )
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// New column: Column 6
dt << New Column( "Column 6",
	Numeric,
	"Continuous",
	Format( "Best", 12 )
);

dt << Move Selected Columns( {:Column 6}, after( :sex ) );
Jim