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

Topic Options

- Start Article
- 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
(4539 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

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 4

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

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

Re: JLS- Divide Column by a Value

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

Re: JLS- Divide Column by a Value

yes, well spotted. thanks

-Dave

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

Re: JLS- Divide Column by a Value

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