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
geoff1
Level II

Divide column by value from another table

Hello,

I need your help to devide  columns by a variable from another table

dt is a big table with a lot of columns

dt2 has 2 columns "Names" (contains column names from dt)  and "DivideValue"  ( could be 10, 100, 10000,...)

 

I want to divide dt columns by the dt2 Dividevalue IF dt column nane  = dt2 Names.

I could create a new column with formula, then remove property and delete "old column", but I guess we could apply a formula to the curent columns ?

 

I found that we can apply a custom format like below : A/10

Column( "A" ) << set Format( "Custom", Formula( (value/10)) ), 5, 0 );

 

But in the for loop I cannot make it working.

colnamedt = {};	
N = N Col(dt);
R = N Row(dt2);
	
For(k = 1, k <= N, k++,
	colnamedt = Column( dt,k ) << getname();
	for (i=1, i <= R, i++,
		if (( dt2:Names[i]==colname),
	     Column( dt,k ) << set Format( "Custom", Formula( (value/dt2:DivideValue[i]) ), 5, 0 );
		););
     );

 

 

 

Thanks

Geof
    

 

@martindemel 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Divide column by value from another table

JMP can directly reference any specific cell in any open JMP data table, therefore, performing your request is fairly simple

Names Default To Here( 1 );

dt = Data Table( "dt" );
dt2 = Data Table( "dt2" );

For( i = 1, i <= N Rows( dt2 ), i++,
	If( Try( Column( dt, dt2:Names[i] ) << get name, "" ) != "",
		For( k = 1, k < N Rows( dt ), k++,
			Column( dt, dt2:Names[i] )[k] = Column( dt, dt2:Names[i] )[k] / dt2:Divide Value[i]
		)
	)
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Divide column by value from another table

JMP can directly reference any specific cell in any open JMP data table, therefore, performing your request is fairly simple

Names Default To Here( 1 );

dt = Data Table( "dt" );
dt2 = Data Table( "dt2" );

For( i = 1, i <= N Rows( dt2 ), i++,
	If( Try( Column( dt, dt2:Names[i] ) << get name, "" ) != "",
		For( k = 1, k < N Rows( dt ), k++,
			Column( dt, dt2:Names[i] )[k] = Column( dt, dt2:Names[i] )[k] / dt2:Divide Value[i]
		)
	)
);
Jim
geoff1
Level II

Re: Divide column by value from another table

Thank you !!!