cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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

Recommended Articles