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

How do I multiply all data values by a multiplier for each column that is identified in another table?

How do I multiply all data values by a multiplier for each column that is in another table, by column name? (The multiplier table has a column with the column names and a second column with the multipliers to apply to each column in the other table. Not all columns have a multiplier.) I can get as far as adding the multiplier to the data table in its own row, but then I'm stuck. I know I can do it quickly externally but I’m sure there’s a way to do it in JMP.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do I multiply all data values by a multiplier for each column that is identified in another table?

Here is a simple example of changing the values in the Big Class data table, based upon a config data table as you describe.

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

dtConfig = New Table( "Config",
	New Column( "Name", character, values( {"age", "height", "weight"} ) ),
	New Column( "multiplier", values( {3, ., 2} ) )
);

dtColNames = dt << get column names( string );

For( i = 1, i <= N Rows( dtConfig ), i++,
	If( Contains( dtColNames, dtConfig:Name[i] ) & Is Missing( dtConfig:multiplier[i] ) == 0,
		temp = Column( dt, dtConfig:Name[i] ) << get values;
		temp = temp  dtConfig:multiplier[i];
		Column( dt, dtConfig:Name[i] ) << set values( temp );
	)
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How do I multiply all data values by a multiplier for each column that is identified in another table?

Here is a simple example of changing the values in the Big Class data table, based upon a config data table as you describe.

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

dtConfig = New Table( "Config",
	New Column( "Name", character, values( {"age", "height", "weight"} ) ),
	New Column( "multiplier", values( {3, ., 2} ) )
);

dtColNames = dt << get column names( string );

For( i = 1, i <= N Rows( dtConfig ), i++,
	If( Contains( dtColNames, dtConfig:Name[i] ) & Is Missing( dtConfig:multiplier[i] ) == 0,
		temp = Column( dt, dtConfig:Name[i] ) << get values;
		temp = temp  dtConfig:multiplier[i];
		Column( dt, dtConfig:Name[i] ) << set values( temp );
	)
);
Jim
dlifke
Level III

Re: How do I multiply all data values by a multiplier for each column that is identified in another table?

Thanks! I passed it along to the internal customer. I presume the middle section dtConfig would not be necessary, since the multiplier table already exists. (You were just creating a new multiplier table to use on big class as an example.)  In the For loop he'd just replace dtConfig with the name of his multiplier table. Does that sound about right? Thanks again!

txnelson
Super User

Re: How do I multiply all data values by a multiplier for each column that is identified in another table?

You are correct....

Jim