Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Re: How to multiply multiple columns by a constant?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 6, 2012 2:10 PM
(12069 views)

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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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