BookmarkSubscribe

## 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.

-Matt

1 ACCEPTED SOLUTION

Accepted Solutions

## 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 )
);``````

2 REPLIES 2

## 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 )
);``````

## 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 ),

);
);``````