cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
katharina_l
Level III

Get distinct entries from a list?

is there a simple way to obtain the distinct entries in a list? (similar to summary of a table by grouping column in order to get distinct entries in that column)
The result could be either a reduced list containing only the distinct entries (repeated ones removed) or just a number showing the amount of different entries.
Before writing a script I would like to check if there is a simple way / function / formula. Couldn't find anything in the JMP help ...

13 REPLIES 13
pmroz
Super User

Re: Get distinct entries from a list?

FWIW here's a unique values function I wrote a while ago:

/*
Function Name: get_unique_values
Description: Find the unique values in a list.  Uses an associative array
Arguments:
in_list		List to get unique values for
*/
Get_unique_values = Function( {in_list},
      {Default Local}, 
      tmp = [=> 0]; 
      Insert Into( tmp, in_list ); 
      tmp << get keys; 
); 

Sample calls:

a = {1, 1, 1, 2, 3, 3, 3};
b = get_unique_values(a);
print(b);

c = {"Hello", "World", "John", "Ed", "John", "World"};
d = get_unique_values(c);
print(d);

Output:

{1, 2, 3}
{"Ed", "Hello", "John", "World"}
jthi
Super User

Re: Get distinct entries from a list?

How complicate sequences do you have (are they just single letter?)? Do you know beforehand what they could potentially be? And how long can the sequence be?

 

For just calculating the amount of entries, you can use combination of N Items + Associative Array and Words

 

N Items(Associative Array(Words(:sequence, "|")))

Partially relatedProvide fast way to get unique values from JMP objects (column, lists), possibly similar to Python's... 

 

-Jarmo
hogi
Level XII

Re: Get distinct entries from a list?


@jthi wrote:
N Items(Associative Array(Words(:sequence, "|")))

 

Maybe I am wrong, but this suggestion looks very similar to what @katharina_l posted in 
https://community.jmp.com/t5/Discussions/Get-distinct-entries-from-a-list/m-p/820530/highlight/true#... ? ?

katharina_l
Level III

Re: Get distinct entries from a list?

thank you Holger and yes, definitely looks like the function I was looking for. Would be great if it could be implemented as a standard function in JMP.