cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-51256%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERufen%20Sie%20eine%20Liste%20der%20eindeutigen%20Werte%20in%20einer%20Spalte%2C%20Matrix%20oder%20Liste%20ab%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-51256%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CDIV%20class%3D%22lia-message-template-problem-zone%22%3EProblem%3CP%3EProblem%201%3A%20Ich%20ben%C3%B6tige%20eine%20Liste%20der%20eindeutigen%20Werte%20in%20einer%20Datentabellenspalte.%3C%2FP%3E%3CP%3EProblem%202%3A%20Ich%20ben%C3%B6tige%20eine%20Liste%20der%20eindeutigen%20Werte%20in%20einer%20JSL-Datenstruktur%20(Liste%20oder%20Matrix)%3C%2FP%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3EL%C3%B6sung%3CP%3E%3CU%3EZu%20Problem%201%3A%3C%2FU%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3EL%C3%B6sung%201%3A%3C%2FSTRONG%3E%20Verwenden%20Sie%20%C3%9Cbersichtstabellen.Die%20folgende%20JSL%20zeigt%2C%20wie%20Sie%20mit%20Summary()%20eine%20Tabelle%20erhalten%2C%20die%20eine%20Zeile%20mit%20jedem%20eindeutigen%20Wert%20in%20einer%20einzelnen%20Spalte%20enth%C3%A4lt.Anschlie%C3%9Fend%20k%C3%B6nnen%20Sie%20weitere%20JSL-Tabellenbefehle%20ausf%C3%BChren%2C%20um%20diese%20Werte%20aus%20der%20%C3%9Cbersichtstabelle%20abzurufen.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E_dt%20%3D%20Open(%20%22%24sample_data%2Fbig%20class.jmp%22%20)%3B%0A%2F%2Fcreate%20a%20summary%20table%20of%20the%20%3Asex%20column%0A_dt1%20%3D%20_dt%20%26lt%3B%26lt%3B%20Summary(%0A%20Group(%20%3Asex%20)%2C%0A%20Freq(%20%22None%22%20)%2C%0A%20Weight(%20%22None%22%20)%0A)%3B%0A%2F%2Fcreate%20a%20summary%20table%20of%20the%20%3Aage%20column%0A_dt2%20%3D%20_dt%20%26lt%3B%26lt%3B%20Summary(%0A%20Group(%20%3Aage%20)%2C%0A%20Freq(%20%22None%22%20)%2C%0A%20Weight(%20%22None%22%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%222-13-2018%205-22-08%20PM.png%22%20style%3D%22width%3A%20280px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%222-13-2018%205-22-08%20PM.png%22%20style%3D%22width%3A%20280px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%222-13-2018%205-22-08%20PM.png%22%20style%3D%22width%3A%20280px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F9328i5A075F342798D202%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%222-13-2018%205-22-08%20PM.png%22%20alt%3D%222-13-2018%205-22-08%20PM.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FCODE%3E%3C%2FP%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CU%3EProblem%202%3A%3C%2FU%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3EAnstelle%20einer%20Datentabelle%20haben%20Sie%20jetzt%20eine%20JMP-Liste%20oder%20-Matrix%3A%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Esexlist%20%3D%20%7B%22F%22%2C%20%22M%22%2C%20%22M%22%2C%20%22F%22%2C%20%22F%22%2C%20%22M%22%2C%20%22M%22%2C%20%22F%22%2C%20%22M%22%7D%3B%0Aagelist%20%3D%20%5B14%2C%2011%2C%2012%2C%2013%2C%2015%2C%2017%2C%2015%2C%2011%2C%2012%5D%3B%3C%2FCODE%3E%3C%2FPRE%3EDie%20komplizierten%20M%C3%B6glichkeiten%2C%20dies%20zu%20tun%2C%20w%C3%A4ren%3A%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3Ea)%20F%C3%BCgen%20Sie%20die%20Werte%20in%20der%20Liste%20in%20eine%20neue%20Datentabellenspalte%20ein%20und%20verwenden%20Sie%20dann%20den%20Zusammenfassungsansatz%20ODER%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3Eb)%20Schreiben%20Sie%20eine%20etwas%20komplizierte%20for-Schleife%2C%20um%20nach%20eindeutigen%20Werten%20zu%20suchen%20und%20diese%20aufzuzeichnen%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3EGl%C3%BCcklicherweise%20gibt%20es%20einen%20einfacheren%20Weg%3A%20die%20Verwendung%20assoziativer%20Arrays.%26nbsp%3B%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EAssociative%20Array(sexlist)%20%26lt%3B%26lt%3B%20Get%20Keys%3B%0AAssociative%20Array(agelist)%20%26lt%3B%26lt%3B%20Get%20Keys%3B%3C%2FCODE%3E%3C%2FPRE%3Egibt%20%7B%22F%22%2C%20%22M%22%7D%20bzw.%20%7B11%2C%2012%2C%2013%2C%2014%2C%2015%2C%2017%7D%20zur%C3%BCck%20(beachten%20Sie%2C%20dass%20es%20sich%20um%20eine%20gut%20sortierte%20Liste%20handelt!).Wenn%20Sie%20die%20numerischen%20Werte%20als%20sortierten%20Vektor%20m%C3%B6chten%2C%20k%C3%B6nnen%20Sie%20verwenden%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EMatrix(Associative%20Array(agelist)%20%26lt%3B%26lt%3B%20Get%20Keys)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3Ewas%20%5B11%2C%2012%2C%2013%2C%2014%2C%2015%2C%2017%5D%20zur%C3%BCckgibt.%26nbsp%3B%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3EDieser%20Ansatz%20kann%20auch%20anstelle%20von%20L%C3%B6sung%201%20f%C3%BCr%20Problem%201%20verwendet%20werden%3A%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CU%3EProblem1%2C%20L%C3%B6sung%202%3A%3C%2FU%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EAssociative%20Array(Column(_dt%2C%20%22sex%22)%20%26lt%3B%26lt%3B%20Get%20Values)%20%26lt%3B%26lt%3B%20Get%20Keys%3B%3CBR%20%2F%3EMatrix(Associative%20Array(Column(_dt%2C%20%22age%22)%26lt%3B%26lt%3B%20Get%20Values)%26lt%3B%3CGET%20keys%3D%22%22%3E%3C%2FGET%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3Ekehrt%20zur%C3%BCck%3CSPAN%3E%20%7B%22F%22%2C%20%22M%22%7D%20bzw.%20%5B11%2C%2012%2C%2013%2C%2014%2C%2015%2C%2017%5D.%20Was%20dies%20bewirkt%2C%20ist%3C%2FSPAN%3E%3C%2FDIV%3E%3CUL%3E%3CLI%3E%3CSPAN%3ERufen%20Sie%20die%20Werte%20aus%20der%20angegebenen%20Spalte%20als%20Liste%20(wenn%20die%20Spalte%20ein%20Zeichen%20ist)%20oder%20als%20Matrix%20(wenn%20die%20Spalte%20numerisch%20ist)%20ab.%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3EVerwandeln%20Sie%20diese%20Liste%20oder%20Matrix%20in%20ein%20assoziatives%20Array%3C%2FLI%3E%3CLI%3ERufen%20Sie%20die%20Schl%C3%BCssel%20f%C3%BCr%20das%20assoziative%20Array%20ab%2C%20in%20diesem%20Fall%20die%20eindeutigen%20Ebenen%20der%20Werte%20in%20der%20Spalte%2C%20und%20geben%20Sie%20diese%20als%20Liste%20zur%C3%BCck%3C%2FLI%3E%3CLI%3E(Wenn%20Matrix()%20f%C3%BCr%20die%20resultierende%20Liste%20verwendet%20wird%2C%20funktioniert%20es%20nur%2C%20wenn%20die%20Werte%20in%20der%20Liste%20alle%20Zahlen%20sind).%3C%2FLI%3E%3C%2FUL%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-220875%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Eine%20Liste%20der%20eindeutigen%20Werte%20in%20einer%20Spalte%2C%20Matrix%20oder%20Liste%20abrufen%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-220875%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESummarize()%20ist%20viel%20effizienter%20als%20assoziative%20Arrays%2C%20was%20bei%202%20Millionen%20Datenzeilen%20(1%20Sekunde%20gegen%C3%BCber%208%20Sekunden%20Zeitraffer)%20sehr%20deutlich%20wird.%20Wenn%20die%20Leistung%20entscheidend%20ist%2C%20verwenden%20Sie%20nach%20M%C3%B6glichkeit%20Summarize().%3C%2FP%3E%3CP%3ESummarize(%20dt%2C%20smrz1%20%3D%20by(%20%3Asex%20)%20)%3B%20Summarize(%20dt%2C%20smrz2%20%3D%20by(%20%3Aage%20)%20)%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E*%20Summarize()%20erstellt%20keine%20Zwischendatentabelle%20als%20%26lt%3B%26lt%3B%20Zusammenfassung%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAssoziative%20Arrays%20sind%20insofern%20gro%C3%9Fartig%2C%20als%20sie%20den%20Aufwand%20sparen%2C%20die%20Liste%2FMatrix%20in%20eine%20Datentabelle%20einzuf%C3%BCgen.%20Dies%20ist%20die%20perfekte%20L%C3%B6sung%20f%C3%BCr%20kleine%20Datenmengen.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Get a list of the unique values in a column, matrix, or list
Problem

Problem 1:  I need to get a list of the unique values in a data table column.

Problem 2:  I need to get a list of the unique values in a JSL data structure (list or matrix)

Solution

For problem 1:

Solution 1:  Use summary tables.  The JSL below shows how to use Summary() to get a table that will have a row with each unique value in a single column.   You can then do further JSL table commands to get those values from the summary table. 

 

_dt = Open( "$sample_data/big class.jmp" );
//create a summary table of the :sex column
_dt1 = _dt << Summary(
	Group( :sex ),
	Freq( "None" ),
	Weight( "None" )
);
//create a summary table of the :age column
_dt2 = _dt << Summary(
	Group( :age ),
	Freq( "None" ),
	Weight( "None" )
);

2-13-2018 5-22-08 PM.png

 
Problem 2:  
Now,  instead of a data table you have a JMP list or matrix:
sexlist = {"F", "M", "M", "F", "F", "M", "M", "F", "M"};
agelist = [14, 11, 12, 13, 15, 17, 15, 11, 12];
the complicated ways to do this would be:
a) put the values in the list into a new data table column, and then use the summary approach, OR
b) write a somewhat complicated for loop to search for and record unique values
 
Fortunately, there is an easier way, using associative arrays.  
Associative Array(sexlist) << Get Keys;
Associative Array(agelist) << Get Keys;
returns {"F", "M"} and {11, 12, 13, 14, 15, 17}, respectively (note that these are nice sorted list!).  If you would like the numeric values as a sorted vector, you can use
Matrix(Associative Array(agelist) << Get Keys);
which returns [11, 12, 13, 14, 15, 17].  
 
This approach can also be used in place of Solution 1 for Problem 1:
 
Problem1, Solution 2:
Associative Array(Column(_dt, "sex") << Get Values) << Get Keys;
Matrix(Associative Array(Column(_dt, "age")<< Get Values)<<Get Keys);
returns {"F", "M"} and [11, 12, 13, 14, 15, 17]., respectively. What this is doing is 
  • get the values from the specified column as a list (if the column is character) or a matrix (if the column is numeric)
  • turn that list or martrix into an associative array
  • get the keys for the associative array, which in this case are the unique levels of the values in the column, returning that as a list
  • (if Matrix() is used on the resulting list, it will only work if the values in the list are all numbers).
 
Comments
HP_Lau

Summarize() is way much more efficient than associative array, it is very obvious with 2 million rows of data (1sec vs 8sec time lapse). If performance is critical, use Summarize() whenever possible.

Summarize( dt, smrz1 = by( :sex ) ); Summarize( dt, smrz2 = by( :age ) );

* Summarize() does not create intermediate data table as << Summary

 

Associative Array is great in the way that it saves the effort to put the list/matrix into data table, this is perfect solution for small data size.

 

JSL Cookbook

If you’re looking for a code snippet or design pattern that performs a common task for your JSL project, the JSL Cookbook is for you.

This knowledge base contains building blocks of JSL code that you can use to reduce the amount of coding you have to do yourself.

It's also a great place to learn from the experts how to use JSL in new ways, with best practices.