cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
natalie_
Level V

JLS- Divide Column by a Value

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
David_Burnham
Super User (Alumni)

Re: JLS- Divide Column by a Value

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

View solution in original post

4 REPLIES 4
David_Burnham
Super User (Alumni)

Re: JLS- Divide Column by a Value

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
txnelson
Super User

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
David_Burnham
Super User (Alumni)

Re: JLS- Divide Column by a Value

yes, well spotted.  thanks

-Dave
natalie_
Level V

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