cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Mcc99
Level I

Script to create a new data table by subtracting one data table from another.

I have two data tables in my project and am trying to write a script that would like to create a third data table which is the values in table #2 subtracted from table #1. Categorical variable columns and column names are the same in both tables and would need to be the same in table #3. I'm using JMP pro 16. 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Script to create a new data table by subtracting one data table from another.

I don't really use projects, but this can give you one idea for the script using Data table subscripting (it assumes both have same amount of rows and columns)

Names Default To Here(1);

dt = New Table("Untitled 2",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("Column 1", Character, "Nominal", Set Values({"A", "B", "C"})),
	New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3])),
	New Column("Column 3", Numeric, "Continuous", Format("Best", 12), Set Values([4, 6, 8]))
);

dt2 = New Table("Untitled 2",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("Column 1", Character, "Nominal", Set Values({"A", "B", "C"})),
	New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([2, 3, 4])),
	New Column("Column 3", Numeric, "Continuous", Format("Best", 12), Set Values([8, 12, 18]))
);

dt3 = dt2 << Subset(All Rows, Seleted Columns(0));

cont_cols = dt2 << Get Column Names(Continuous, "String");

dt3[0, cont_cols] = dt3[0, cont_cols] - dt[0, cont_cols];
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Script to create a new data table by subtracting one data table from another.

I don't really use projects, but this can give you one idea for the script using Data table subscripting (it assumes both have same amount of rows and columns)

Names Default To Here(1);

dt = New Table("Untitled 2",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("Column 1", Character, "Nominal", Set Values({"A", "B", "C"})),
	New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3])),
	New Column("Column 3", Numeric, "Continuous", Format("Best", 12), Set Values([4, 6, 8]))
);

dt2 = New Table("Untitled 2",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("Column 1", Character, "Nominal", Set Values({"A", "B", "C"})),
	New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([2, 3, 4])),
	New Column("Column 3", Numeric, "Continuous", Format("Best", 12), Set Values([8, 12, 18]))
);

dt3 = dt2 << Subset(All Rows, Seleted Columns(0));

cont_cols = dt2 << Get Column Names(Continuous, "String");

dt3[0, cont_cols] = dt3[0, cont_cols] - dt[0, cont_cols];
-Jarmo
Mcc99
Level I

Re: Script to create a new data table by subtracting one data table from another.

Thanks! This worked well!