- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 )-1, k++,For( i = k+1, i <= N Items( uniqNames ), i++,if (i > k, Eval(EvalExpr(Current Data Table() << New Column(Char(uniqNames[k])||" - "||Char(uniqNames[i])||" Matrix", Numeric, "Continuous", Format("Best", 10), Formula(Col Maximum(If(Contains(:Level, Expr(Char(uniqNames[i])), 1), As Column(Expr(Char(uniqNames[k])))), :Group, :Size))););))));
Solved: Get column values using Loop - JMP User Community
Slán
SpannerHead
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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]
- How to randomly assign one value to three unique IDs, while having each ID assigned 6 unique values?
- Combinations of a list put into columns
- JMP can generate all possible combinations of 40 numbers in groups of 6 numbers without repetition?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 )-1, k++,For( i = k+1, i <= N Items( uniqNames ), i++,if (i > k, Eval(EvalExpr(Current Data Table() << New Column(Char(uniqNames[k])||" - "||Char(uniqNames[i])||" Matrix", Numeric, "Continuous", Format("Best", 10), Formula(Col Maximum(If(Contains(:Level, Expr(Char(uniqNames[i])), 1), As Column(Expr(Char(uniqNames[k])))), :Group, :Size))););))));
Solved: Get column values using Loop - JMP User Community
Slán
SpannerHead
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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();