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
- :
- JLS- Divide Column by a Value

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
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 7, 2016 1:41 PM
(1586 views)

Hi again,

I am writing some script which opens several csv files and joins them; it is working well!

In one column, I'd like to divide the values of another column by a value. I just can't figure it out. I can do it on the formula editor though, but I don't believe I can use that syntax while scripting.

dt << New Column("."); //just to create a blank column

dt << New Column("Id(A/mm)");

col = Column("Id(A/mm)");

col << Set Formula(Column("Id(A)")/Wg);

col << EvalFormula;

[code/]

1 ACCEPTED SOLUTION

Accepted Solutions

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

Jan 7, 2016 2:46 PM
(2898 views)

Solution

something like this maybe:

someNumbers = **1**::**10**;

New Table**(**"demo",

Add Rows**(****10)**,

New Column**(**"Sequence", numeric, continuous, <<**Set Values****(**someNumbers**)** **)**

**)**;

col = New Column**(**".", numeric, continuous**)**;

valueToDivideBy = **2**;

col << **Set Formula(**:Sequence/valueToDivideBy**)**;

// or ...

col = New Column**(**"..", numeric, continuous**)**;

col << **Set Formula(** AsColumn**(**"Sequence"**)**/**2)**;

-Dave

4 REPLIES

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

Jan 7, 2016 2:46 PM
(2899 views)

something like this maybe:

someNumbers = **1**::**10**;

New Table**(**"demo",

Add Rows**(****10)**,

New Column**(**"Sequence", numeric, continuous, <<**Set Values****(**someNumbers**)** **)**

**)**;

col = New Column**(**".", numeric, continuous**)**;

valueToDivideBy = **2**;

col << **Set Formula(**:Sequence/valueToDivideBy**)**;

// or ...

col = New Column**(**"..", numeric, continuous**)**;

col << **Set Formula(** AsColumn**(**"Sequence"**)**/**2)**;

-Dave

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

Jan 7, 2016 5:44 PM
(1449 views)

There is an issue with the first solution provided by David. While the code will work, the formula created is:

:Sequence/valueToDivideBy

Since "valueToDivideBy" is a scalar memory variable, that will go away once the JMP session is closed, or could change value during the course of the day's processing, the calculated value of "col" could become invalid or incorrect. The second version of the formula would be preferred. However, if you want to use the structure of the first solution, you could do a couple of things:

1. Change the Se Formula to:

col << Set Formula(Eval(Parse(":Sequence/"||char(valueToDivideBy)));

2. Convert the formula to static values once the formula has been applied. To do this, add the following line after the the col << Set Formula line

col << delete property("formula");

Jim

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

Jan 8, 2016 12:20 AM
(1449 views)

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

Jan 8, 2016 8:17 AM
(1449 views)

I chose to use David's second method. I think I understand why his first method has an issue, but I was unable to make your suggested changes. As I run the script, I can make all the new column, but the formulas are not working.

col= new column("."); //add blank column

col=New Column("Id(A/mm)",numeric,continuous);

col<<Set Formula(Eval,Parse(":Id(A)/"||Char(Wg)));

col<<delete property(":Id(A)/"||Char(Wg));