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
- :
- How to multiply multiple columns by a constant?

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

Highlighted

- 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
(14310 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

Created:
Jun 6, 2012 2:30 PM
| Last Modified: Jun 15, 2018 5:41 AM
(19526 views)
| Posted in reply to message from matt_p 06-06-2012

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

Created:
Jun 6, 2012 2:30 PM
| Last Modified: Jun 15, 2018 5:41 AM
(19527 views)
| Posted in reply to message from matt_p 06-06-2012

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

Highlighted
##

- 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?

Created:
Jun 7, 2012 8:36 AM
| Last Modified: Jun 15, 2018 5:41 AM
(13626 views)
| Posted in reply to message from ms 06-06-2012

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

Article Labels

There are no labels assigned to this post.