cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
SpannerHead
Level IV

Iteratively Create Columns Containing All Permutations of Subtraction from an Initial List of Columns

I have a list of columns and I need to create a new series of columns with every permutation of the difference between the listed columns.  The number of the columns in the list can vary and the non-iterative example below covers 3 columns (12 to 14).

 

Current  Data Table() << New Column(Head Name( As Namespace( Column( 12 ) ) )||" - "||Head Name( As Namespace( Column( 13 ) ) )||" HSD Threshold Matrix", Numeric, "Continuous", Format("Best", 10), Formula(Col Maximum(If(Contains(:Level, Head Name(As Namespace(Column(13))), 1), As Column(12)), :Group, :Size)));

Current  Data Table() << New Column(Head Name( As Namespace( Column( 12 ) ) )||" - "||Head Name( As Namespace( Column( 14 ) ) )||" HSD Threshold Matrix", Numeric, "Continuous", Format("Best", 10), Formula(Col Maximum(If(Contains(:Level, Head Name(As Namespace(Column(14))), 1), As Column(12)), :Group, :Size)));

Current  Data Table() << New Column(Head Name( As Namespace( Column( 13 ) ) )||" - "||Head Name( As Namespace( Column( 14 ) ) )||" HSD Threshold Matrix", Numeric, "Continuous", Format("Best", 10), Formula(Col Maximum(If(Contains(:Level, Head Name(As Namespace(Column(14))), 1), As Column(13)), :Group, :Size)));

 

 


Slán



SpannerHead
1 ACCEPTED SOLUTION

Accepted Solutions
SpannerHead
Level IV

Re: Iteratively Create Columns Containing All Permutations of Subtraction from an Initial List of Columns

Not sure if this is what you meant but I found something here that works.  What's even better about this is that it doesn't rely on column numbers.

Names Default to Here(1);
dt = Current Data Table();

//Select X Variable ____________________________________________________________________________________________________________________________________________

cdb = Column Dialog("Add continuous variables you want to plot as X" ,
	colxx = ColList( "X", Min Col( 1 ) ),
);
show(cdb);
Eval List(cdb[1::N Items(cdb)-1]);

Summarize(dt, uniqNames = by(colxx[1]));
Show(uniqNames);
Num = NItems(uniqNames);



For( k = 1, k <= N Items( uniqNames ), k++,
	// Loop through all columns finding non NA values
	For( i = 2, i <= N Items( uniqNames ), i++,
		if (i > k, Current  Data Table() << New Column(Char(uniqNames[k])||" - "||Char(uniqNames[i])||" Matrix", Numeric, "Continuous", Format("Best", 10), Formula(Col Maximum(If(Contains(:Level, Char(uniqNames[i]), 1), As Column(uniqNames[k])), :Group, :Size)));
			)
		)
	)
;

 

Solved: Get column values using Loop - JMP User Community

 

 


Slán



SpannerHead

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Iteratively Create Columns Containing All Permutations of Subtraction from an Initial List of Columns

You can for example use NChooseK Matrix() to create the combinations (or DoE)

 

Names Default To Here(1);

mylist = {12, 13, 14};
possible_group_idx = NChooseK Matrix(3,2);

my_groups = Transform Each({idx}, possible_group_idx,
	mylist[idx]
);
[12 13, 12 14, 13 14]

 

 

-Jarmo
SpannerHead
Level IV

Re: Iteratively Create Columns Containing All Permutations of Subtraction from an Initial List of Columns

Jarmo

 

Thanks, looks like it will work.  Haven't had time to study the details but wondering if there's an example of how it can be employed?


Slán



SpannerHead
jthi
Super User

Re: Iteratively Create Columns Containing All Permutations of Subtraction from an Initial List of Columns

Loop over the matrix (or turn it into list of lists) and create the columns as you do that.

-Jarmo
SpannerHead
Level IV

Re: Iteratively Create Columns Containing All Permutations of Subtraction from an Initial List of Columns

Not sure if this is what you meant but I found something here that works.  What's even better about this is that it doesn't rely on column numbers.

Names Default to Here(1);
dt = Current Data Table();

//Select X Variable ____________________________________________________________________________________________________________________________________________

cdb = Column Dialog("Add continuous variables you want to plot as X" ,
	colxx = ColList( "X", Min Col( 1 ) ),
);
show(cdb);
Eval List(cdb[1::N Items(cdb)-1]);

Summarize(dt, uniqNames = by(colxx[1]));
Show(uniqNames);
Num = NItems(uniqNames);



For( k = 1, k <= N Items( uniqNames ), k++,
	// Loop through all columns finding non NA values
	For( i = 2, i <= N Items( uniqNames ), i++,
		if (i > k, Current  Data Table() << New Column(Char(uniqNames[k])||" - "||Char(uniqNames[i])||" Matrix", Numeric, "Continuous", Format("Best", 10), Formula(Col Maximum(If(Contains(:Level, Char(uniqNames[i]), 1), As Column(uniqNames[k])), :Group, :Size)));
			)
		)
	)
;

 

Solved: Get column values using Loop - JMP User Community

 

 


Slán



SpannerHead
jthi
Super User

Re: Iteratively Create Columns Containing All Permutations of Subtraction from an Initial List of Columns

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Cities.jmp");

mycols = {"OZONE", "CO", "SO2", "NO", "PM10"};

possible_group_idx = NChooseK Matrix(N Items(mycols), 2);
my_groups = Transform Each({idx}, As List(possible_group_idx), Output("List"),
	mycols[idx]
);

For Each({cols}, my_groups,
	Eval(Substitute(
		Expr(dt << New Column(cols[1] ||"_"||cols[2], Numeric, Continuous,
			Formula(_col1_ + _col2_)
		)),
		Expr(_col1_), Name Expr(AsColumn(dt, cols[1])),
		Expr(_col2_), Name Expr(AsColumn(dt, cols[2]))
	));
);

Write();
-Jarmo