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
razmah
Level II

set a formula for columns with variable name

I have 3 columns with variable names.

how can I add new column and give it a formula by use of a,b, and c?

I wrote following script but column doesn't show the formula.

New Column( "a /b",Numeric,Continuous,Format( "Best", 12 ),

Formula( :column(char(a)) /  :column( char(b)) ));

thank you for your recommendation

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: set a formula for columns with variable name

Ah OK.  Here's a better example:

a = 10;

b = 20;

dt = New Table( "Example", Add Rows( 3 ),

     New Column( char(a), Numeric, Continuous, Format( "Best", 12 ),

           Set Values( [1, 2, 3] ) ),

     New Column( char(b), Numeric, Continuous, Format( "Best", 12 ),

           Set Values( [4, 5, 6] ) ),

);

new_expr = evalinsert(

"\[dt << New Column( "a/b", Numeric, Continuous, Format( "Best", 12 ),

     Formula( :Name( "^a^" ) / :Name( "^b^" )))]\");

eval(parse(new_expr));

View solution in original post

6 REPLIES 6
pmroz
Super User

Re: set a formula for columns with variable name

This will work:

a = "weight";

b = "height";

dt = open("$sample_data\Big Class.jmp");

new_expr = evalinsert(

"\[dt << New Column( "a/b",Numeric,Continuous,Format( "Best", 12 ),

Formula( :^a^ / :^b^ ))]\");

eval(parse(new_expr));

razmah
Level II

Re: set a formula for columns with variable name

My "a" and "b" are not name; thay are numbers.

do I need any changes for that? because I tried your script, it didn't work for me.

pmroz
Super User

Re: set a formula for columns with variable name

Ah OK.  Here's a better example:

a = 10;

b = 20;

dt = New Table( "Example", Add Rows( 3 ),

     New Column( char(a), Numeric, Continuous, Format( "Best", 12 ),

           Set Values( [1, 2, 3] ) ),

     New Column( char(b), Numeric, Continuous, Format( "Best", 12 ),

           Set Values( [4, 5, 6] ) ),

);

new_expr = evalinsert(

"\[dt << New Column( "a/b", Numeric, Continuous, Format( "Best", 12 ),

     Formula( :Name( "^a^" ) / :Name( "^b^" )))]\");

eval(parse(new_expr));

razmah
Level II

Re: set a formula for columns with variable name

GREAT! Thanks

pmroz
Super User

Re: set a formula for columns with variable name

For those not familiar with evalinsert or \[...]\:

evalinsert allows the insertion of variables surrounded by the caret character "^".  Makes it easier to build a string containing variables by avoiding lots of concatenating.

The special characters \[ in a string tell JMP not to interpret anything in the string, until you see the characters ]\.  Allows for clean insertion of double quotes, among other things.

gutloja
Level III

Re: set a formula for  columns with variable name

Hello, Razmah.

If all you want is to insert a new column to an already open file, with a formula using "A", "B, and "C" columns [from your data table], just run a similar script on your Script Editor:

    New Column( "A/B", Numeric, Continuous, Format( "Best", 5 ), Formula( a / b ) );

    New Column( "B/C", Numeric, Continuous, Format( "Best", 5 ), Formula( b / c ) );

    New Column( "C*D", Numeric, Continuous, Format( "Best", 5 ), Formula( c * d ) );

    New Column( "A+C+B", Numeric, Continuous,Format( "Best", 5 ),Formula( a + b + c));

Your script is missing the "Formula ( ) " function.

-Jose