cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
miguello
Level VII

How to index list with a nested list

Based on https://community.jmp.com/t5/Discussions/Combinations-of-a-list-put-into-columns/m-p/555454

 

I have a list 

list = {"A", "B", "C"}

I need based on that make a list of all pair combinations.

 

Link above helped me to get away from long cycles or joining tables into essentially a one-liner thanks to @brady_brady 

I have this so far:

list = {"A", "B", "C"};
combinations = As List(N Choose K Matrix(N Items(list), 2));

What it does it gives me a list of lists of INDICES

{{1, 2}, {1, 3}, {2, 3}}

and what I need is list of pairs of strings:

{{"A", "B"},{"A", "C"},{"B", "C"}}

without going into cycles is there another one-liner that would do that?

Just indexing list with combinations gives me a flat list

list[combinations]
{"A", "B", "A", "C", "B", "C"}

 

 

4 REPLIES 4
jthi
Super User

Re: How to index list with a nested list

I think you could do it with substitute

Names Default To Here(1);

l = {"A", "B", "C"};
combinations = As List(N Choose K Matrix(N Items(l), 2));
a = Substitute(combinations, 1 ,"A", 2, "B", 3, "C");

but looping is more clear in my opinion

-Jarmo
miguello
Level VII

Re: How to index list with a nested list

Yeah, the list is not known at the compile time, so I guess I'll have to do it through loops.

 

jthi
Super User

Re: How to index list with a nested list

I think something like this should work with Transform Each

l1 = Transform Each({idx}, combinations, l[idx]);
-Jarmo

Re: How to index list with a nested list

This is technically a loop but will also work (assuming you've got lis = the list of values and combinations = the nchoosek matrix of pairs)

 

i = 1;
res = Repeat( { lis[ combinations[ i++, 0 ] ] } , N Items( lis ) );



Recommended Articles