cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar

How to calculate the difference between two identical tables ?

Hi,

I have two identical tables of test results from two different times.

Is there a simple function that can calculate the difference for each case?

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to calculate the difference between two identical tables ?

And this would be the idea using data table subscripting and creating a new table

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = Open("$SAMPLE_DATA/Big Class Families.jmp");
dt2 << Sort(By(:sports),Replace Table,Order(Ascending),Copy formula(0)); // demo purposes

If(N Rows(dt) != N Rows(dt),
	Throw("Rows do not match");
);

cont_cols1 = dt << Get Column Names(Continuous, "String");
cont_cols2 = dt2 << Get Column Names(Continuous, "String");

If(cont_cols1 != cont_cols2,
	Throw("Columns do not match");
);

res = dt[0, cont_cols1] - dt2[0, cont_cols2];

dt_res = As Table(res);
For Each({colname, idx}, cont_cols1,
	Column(dt_res, idx) << Set Name(colname);
);
-Jarmo

View solution in original post

7 REPLIES 7
jthi
Super User

Re: How to calculate the difference between two identical tables ?

I'm not sure what the identical means here (in identical tables the difference would be 0?). Do you have same column names? Where should the result be stored? What is "each case", difference of columns?  

-Jarmo

Re: How to calculate the difference between two identical tables ?

Hi,

Thanks for you reply.

Labels of Colums and Rows are the same. Values are differents. I want to calculate the drift of each cell (sorry not each case).

jthi
Super User

Re: How to calculate the difference between two identical tables ?

Not sure where the results should be calculated, so I will demonstrate fairly simple process which will create new table with the result

 

Join tables together using By Row Number

jthi_0-1748252060834.png

Pick columns in pairs and create the formulas

jthi_1-1748252154731.png

And you should end up with the result columns as formulas

jthi_2-1748252197648.png

-Jarmo
txnelson
Super User

Re: How to calculate the difference between two identical tables ?

Here is a simple script that will take 2 identical all numeric tables....identical in column names and number of rows, and create a new table that is the difference between the 2 tables

names default to here(1);
dt1 = data table("name of first table");
dt2 = data table("name of second table");
// Create a new table from one of the 2 tables
dt3 = dt1 << subset( selected rows(0), selected columns(0));
// Replace cell values in the third data table with the 
// differences between table 1 and table 2
dt3[0,0] = dt1[0,0]-dt2[0,0];

 

Jim
Craige_Hales
Super User

Re: How to calculate the difference between two identical tables ?

If the table is all numeric, you could use data table subscripting to make a pair of matrices and subtract them, then write them back to a new table.
With a little more work, you could do the same thing by choosing just the numeric columns.
Craige
jthi
Super User

Re: How to calculate the difference between two identical tables ?

And this would be the idea using data table subscripting and creating a new table

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = Open("$SAMPLE_DATA/Big Class Families.jmp");
dt2 << Sort(By(:sports),Replace Table,Order(Ascending),Copy formula(0)); // demo purposes

If(N Rows(dt) != N Rows(dt),
	Throw("Rows do not match");
);

cont_cols1 = dt << Get Column Names(Continuous, "String");
cont_cols2 = dt2 << Get Column Names(Continuous, "String");

If(cont_cols1 != cont_cols2,
	Throw("Columns do not match");
);

res = dt[0, cont_cols1] - dt2[0, cont_cols2];

dt_res = As Table(res);
For Each({colname, idx}, cont_cols1,
	Column(dt_res, idx) << Set Name(colname);
);
-Jarmo

Re: How to calculate the difference between two identical tables ?

Thank you for your help. It works.

Recommended Articles