cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
matt_p
Level II

How to multiply multiple columns by a constant?

I am working with a data table near ~250 columns. For about half of the columns, I need to multiply the column by 1000 (for mA).

I would like to do this without having to create a new column every time (reassigning the column).

Throwing this code into my script, I  have

DataTable("Temp")<< (:Col_To_Multiply *= 1000);

This equation is not changing my column at all, and its also not throwing any errors.

This is only for one column, and keep in mind I need to do this for ~125 columns.

Any ideas on the equation or how to do this dynamically would be great.

Thanks in advance!

-Matt

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to multiply multiple columns by a constant?

Here is one way to do it (the script applies the factor 1000 to all columns. It is rather straighforward to adapt the for-loop to cover only columns of interest, i.e. loop over a list of those columns).

 

 

dt = Current Data Table();
For( i = 1, i <= N Col( dt ), i++,
  Column( i ) << set values( (Column( i ) << get as matrix) * 1000 )
);

 

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to multiply multiple columns by a constant?

Here is one way to do it (the script applies the factor 1000 to all columns. It is rather straighforward to adapt the for-loop to cover only columns of interest, i.e. loop over a list of those columns).

 

 

dt = Current Data Table();
For( i = 1, i <= N Col( dt ), i++,
  Column( i ) << set values( (Column( i ) << get as matrix) * 1000 )
);

 

matt_p
Level II

Re: How to multiply multiple columns by a constant?

Thanks for the help, worked awesome!

 

This was the final code I ended up if anyone else has this question:

 

 

dt = Current Data Table();
For( i = 1, i <= N Col(dt ), i++,
  a=Column(i) << get name;
  if ( contains(a, "Col_To_Multiply"),
  Column( i ) << set values( (Column( i ) << get as matrix) * 1000 ),
 
  );
);