cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
vishwasanj
Level V

JSL:Difference between 2 columns

What if I have 2 columns with column names based on the input of data and I need to subtract them and store it in a column?

It's simple with the column name A and B and you can calculate A-B.

 

If the column name A||cyclecountvalue1 and B||cyclecountvalue2 , it gives me an error saying name unresolved.

 

Should I use associative array or complex function?

 

I really appreciate your help.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Re: JSL:Difference between 2 columns

Assuming that you actually have a data column named A||cyclecountvalue1, then this should work: Name( "A||cyclecountvalue1" ) instead. The problem is that the original column name is not a valid JSL name, but the Name() function will return a valid reference that you can use instead.

View solution in original post

3 REPLIES 3

Re: JSL:Difference between 2 columns

Assuming that you actually have a data column named A||cyclecountvalue1, then this should work: Name( "A||cyclecountvalue1" ) instead. The problem is that the original column name is not a valid JSL name, but the Name() function will return a valid reference that you can use instead.

vishwasanj
Level V

Re: JSL:Difference between 2 columns

cyclecount value keeps changing according to the input of the data. I don't think I can put it under the " ".

New Column( "Delta_1_"||Char(currentcycle3),
Numeric,
Formula( :Data of stack_precyc - :Data of stack_||Char(currentcycle3) )//This does not work

);

Maybe I can loop through the column one by one for both the columns till the end of the rows and calculate the difference. Can anyone help with the syntax?

Thank you

Re: JSL:Difference between 2 columns

I don't recommend using formulas unless the contents of a column must automatically update in the future, after the script is finished.

You could iterate over the rows with For Each Row() function but it would be messier, I think. Instead, vectorize the problem.

You can use this pattern:

data 1 = data column 1 << Get As Matrix;

data 2 = data column 2 << Get As Matrix;

Current Data Table() << New Column( "name", Values( data 1 - data 2 ) );

Of course you would iterate over all possible pairs of columns.