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-240795%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ETrier%20les%20listes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-240795%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CDIV%20class%3D%22lia-message-template-problem-zone%22%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EProbl%C3%A8me%3C%2FSTRONG%3E%3C%2FFONT%3E%3CP%3EVous%20avez%20des%20donn%C3%A9es%20dans%20une%20ou%20plusieurs%20listes%20ou%20vecteurs%20matriciels%20que%20vous%20devez%20trier.%3C%2FP%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CSTRONG%3E%3CFONT%20size%3D%225%22%3ELa%20solution%3C%2FFONT%3E%3C%2FSTRONG%3E%3CP%3EUtilisation%3CEM%3E%20Trier%20la%20liste()%3C%2FEM%3E%20ou%3CEM%3E%20Trier%20la%20liste%20dans()%3C%2FEM%3E%20%2C%3CEM%3E%20Rang()%3C%2FEM%3E%20%2C%20ou%20placez%20les%20listes%20et%20les%20vecteurs%20dans%20un%20tableau%20de%20donn%C3%A9es%20et%20triez-le.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F%2F%20Sort%20List%20example%20(makes%20new%20list)%0Anames%20%3D%20%7B%22fred%22%2C%20%22Andy%22%2C%20%22Rory%22%2C%20%22bess%22%2C%20%22susy%22%2C%20%22perl%22%7D%3B%0Asname%20%3D%20Sort%20List(%20names%20)%3B%0AShow(%20names%2C%20sname%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3Enoms%20%3D%20%7B%22fred%22%2C%20%22Andy%22%2C%20%22Rory%22%2C%20%22bess%22%2C%20%22susy%22%2C%20%22perl%22%7D%26nbsp%3B%3B%3C%2FSTRONG%3E%3C%2FFONT%3E%3CEM%3E%20%2F%2F%20inchang%C3%A9%3C%2FEM%3E%3C%2FP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3Esname%20%3D%20%7B%22Andy%22%2C%20%22bess%22%2C%20%22fred%22%2C%20%22perl%22%2C%20%22Rory%22%2C%20%22susy%22%7D%26nbsp%3B%3B%3C%2FSTRONG%3E%3C%2FFONT%3E%3CEM%3E%20%2F%2F%20tri%C3%A9%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F%2F%20Sort%20List%20Into%20example%20(in-place%20sort)%0Anames%20%3D%20%7B%22fred%22%2C%20%22Andy%22%2C%20%22Rory%22%2C%20%22bess%22%2C%20%22susy%22%2C%20%22perl%22%7D%3B%0ASort%20List%20Into(%20names%20)%3B%0AShow(%20names%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3Enoms%20%3D%20%7B%22Andy%22%2C%20%22bess%22%2C%20%22fred%22%2C%20%22perl%22%2C%20%22Rory%22%2C%20%22susy%22%7D%26nbsp%3B%3B%3C%2FSTRONG%3E%3C%2FFONT%3E%3CEM%3E%20%2F%2F%20tri%C3%A9%20sur%20place%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3ELes%20deux%20exemples%20ci-dessus%20fonctionnent%20sur%20une%20seule%20liste.%20S'il%20y%20a%20une%20deuxi%C3%A8me%20liste%20de%20num%C3%A9ros%20de%20t%C3%A9l%C3%A9phone%2C%20ils%20ne%20collent%20pas%20aux%20noms.%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3EPour%20que%20plusieurs%20listes%20aient%20toutes%20le%20m%C3%AAme%20tri%2C%20vous%20pouvez%20utiliser%20la%20fonction%20Rank().%20Les%20listes%20doivent%20avoir%20le%20m%C3%AAme%20nombre%20d'%C3%A9l%C3%A9ments%20et%20aucune%20valeur%20manquante%20dans%20la%20liste%20des%20cl%C3%A9s%20de%20tri.%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Enames%20%3D%20%7B%22fred%22%2C%20%22Andy%22%2C%20%22Rory%22%2C%20%22bess%22%2C%20%22susy%22%2C%20%22perl%22%7D%3B%0Aphone%20%3D%20%7B%22x321%22%2C%20%22x322%22%2C%20%22x323%22%2C%20%22x324%22%2C%20%22x325%22%2C%20%22x326%22%7D%3B%0Arooms%20%3D%20%7B%221003%22%2C%20%221001%22%2C%20%221005%22%2C%20%221002%22%2C%20%221006%22%2C%20%221004%22%7D%3B%0A%0Arnk%20%3D%20Rank(%20names%20)%3B%20%2F%2F%20%5B2%2C%204%2C%201%2C%206%2C%203%2C%205%5D%0A%0A%2F%2F%20use%20the%20rnk%20vector%20to%20make%20sorted%20lists%20from%20the%20old%20lists%0Asnames%20%3D%20names%5Brnk%5D%3B%0Asphone%20%3D%20phone%5Brnk%5D%3B%0Asrooms%20%3D%20rooms%5Brnk%5D%3B%0A%0AShow(%20snames%2C%20sphone%2C%20srooms%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3Esnames%20%3D%20%7B%22Andy%22%2C%20%22bess%22%2C%20%22fred%22%2C%20%22perl%22%2C%20%22Rory%22%2C%20%22susy%22%7D%26nbsp%3B%3B%3C%2FSTRONG%3E%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3E%20t%C3%A9l%C3%A9phone%20%3D%20%7B%22x322%22%2C%20%22x324%22%2C%20%22x321%22%2C%20%22x326%22%2C%20%22x323%22%2C%20%22x325%22%7D%26nbsp%3B%3B%3C%2FSTRONG%3E%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%3CSTRONG%3E%20salles%20%3D%20%7B%221001%22%2C%20%221002%22%2C%20%221003%22%2C%20%221004%22%2C%20%221005%22%2C%20%221006%22%7D%26nbsp%3B%3B%3C%2FSTRONG%3E%3C%2FFONT%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%3ECi-dessus%2C%20les%20nouvelles%20listes%20avec%20le%20pr%C3%A9fixe%20s%20sont%20toutes%20tri%C3%A9es%20par%20nom.%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%3ESi%20vous%20avez%20plusieurs%20listes%2C%20de%20la%20m%C3%AAme%20longueur%2C%20mais%20appari%C3%A9es%20entre%20les%20listes%2C%20peut-%C3%AAtre%20qu'une%20table%20de%20donn%C3%A9es%20serait%20une%20meilleure%20structure%20de%20donn%C3%A9es.%20Vous%20trouverez%20peut-%C3%AAtre%20plus%20facile%20d'utiliser%20un%20tableau%20car%20vous%20pouvez%20le%20voir%2C%20l'enregistrer%2C%20le%20sous-ensemble%2C%20...Mais%20si%20vous%20avez%20d%C3%A9j%C3%A0%20les%20listes%2C%20vous%20pouvez%20cr%C3%A9er%20une%20table%20%C3%A0%20partir%20d'elles.%20Voici%20une%20fonction%20utilisateur%20r%C3%A9utilisable%20qui%20fait%20cela%26nbsp%3B%3A%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F%2F%20the%20zip%20function%2C%20named%20after%20a%20Python%20function%20that%2C%20like%20a%20zipper%2C%20zips%20two%20lists%20together%0Azip%20%3D%20Function(%20%7BvariableNameList%7D%2C%20%2F%2F%20a%20list%20of%20variable%20names%0A%20%7BiVarName%2C%20dt%2C%20data%7D%2C%20%2F%2F%20local%20variables%0A%20dt%20%3D%20New%20Table(%20%22zip%22%2C%20%22invisible%22%20)%3B%20%2F%2F%20a%20hidden%20table%2C%20returned%20at%20end%20of%20this%20function%0A%20For(%20iVarName%20%3D%201%2C%20iVarName%20%26lt%3B%3D%20N%20Items(%20variableNameList%20)%2C%20iVarName%20%2B%3D%201%2C%0A%20%20data%20%3D%20Eval(%20variableNameList%5BiVarName%5D%20)%3B%20%2F%2F%20makes%20a%20copy%20of%20the%20data%20from%20the%20name%0A%20%20If(%20Is%20Matrix(%20data%20)%20%7C%20Is%20Number(%20data%5B1%5D%20)%2C%20%2F%2F%20handle%20lists%20of%20numbers%20same%20as%20a%20matrix%0A%20%20%20dt%20%26lt%3B%26lt%3B%20New%20Column(%20Char(%20variableNameList%5BiVarName%5D%20)%2C%20%22numeric%22%2C%20values(%20data%20)%2C%0A%20%20%20%20setProperty(%20%22wasMatrix%22%2C%20eval(Is%20Matrix(%20data%20)%20)%20)%20)%20%2F%2F%20remember%20how%20to%20convert%20back%2C%20could%20be%20list%0A%20%20%2C%20%2F%2F%20else%20a%20list%20of%20strings%0A%20%20%20dt%20%26lt%3B%26lt%3B%20New%20Column(%20Char(%20variableNameList%5BiVarName%5D%20)%2C%20%22character%22%2C%20values(%20data%20)%2C%0A%20%20%20%20setProperty(%20%22wasString%22%2C%20eval(%20Is%20String(%20data%5B1%5D%20)%20)%20)%20)%20%2F%2F%20remember%20how%20to%20convert%20back%2C%20could%20be%20names%0A%20%20)%3B%0A%20)%3B%0A%20dt%20%26lt%3B%26lt%3B%20New%20Column(%20%22_original%20order_%22%2C%20values(%201%20%3A%3A%20N%20Rows(%20dt%20)%20)%20)%3B%20%2F%2F%20this%20extra%20column%20is%20not%20required%2C%20but%20might%20be%20useful%0A%20dt%20%26lt%3B%26lt%3B%20setdirty(%200%20)%3B%20%2F%2F%20not%20required%20but%20avoids%20a%20%22save%3F%22%20prompt%0A%20dt%3B%20%2F%2F%20return%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3EExemple%3A%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ecars%20%3D%20%7Bchevy%2C%20volkswagon%2C%20honda%2C%20ford%2C%20toyota%7D%3B%20%2F%2F%20list%20of%20unquoted%20names%0Adoors%20%3D%20%5B4%2C%202%2C%202%2C%205%2C%202%5D%3B%20%2F%2F%20matrix%20of%20numbers%0Amiles%20%3D%20%7B30000%2C%2020000%2C%2040000%2C%2010000%2C%2050000%7D%3B%20%2F%2F%20list%20of%20numbers%0Aowner%20%3D%20%7B%22fred%22%2C%20%22susan%22%2C%20%22ralph%22%2C%20%22penelope%22%2C%20%22terry%22%7D%3B%20%2F%2F%20list%20of%20quoted%20strings%0A%0AzippedDt%20%3D%20zip(%20%7Bcars%2C%20doors%2C%20miles%2C%20owner%7D%20)%3B%0AzippedDt%20%26lt%3B%26lt%3B%20sort(%20by(%20miles%20)%2C%20replacetable(%201%20)%20)%3B%0A%0AzippedDt%20%26lt%3B%26lt%3B%20show%20Window%3B%20%2F%2F%20table%20hidden%20by%20default%3C%2FCODE%3E%3C%2FPRE%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Lists%20are%20in%20table's%20columns%2C%20sorted%20by%20miles%22%20style%3D%22width%3A%20608px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Lists%20are%20in%20table's%20columns%2C%20sorted%20by%20miles%22%20style%3D%22width%3A%20608px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Lists%20are%20in%20table's%20columns%2C%20sorted%20by%20miles%22%20style%3D%22width%3A%20608px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F20924i7EFBFEA1913B75F6%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22sortedTable.PNG%22%20alt%3D%22Lists%20are%20in%20table's%20columns%2C%20sorted%20by%20miles%22%20%2F%3E%3Cspan%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ELists%20are%20in%20table's%20columns%2C%20sorted%20by%20miles%3C%2Fspan%3E%3C%2Fspan%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ELists%20are%20in%20table's%20columns%2C%20sorted%20by%20miles%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ELes%20listes%20sont%20dans%20les%20colonnes%20du%20tableau%2C%20tri%C3%A9es%20par%20miles%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3ESi%20vous%20travaillez%20avec%20des%20listes%2C%20vous%20souhaiterez%20peut-%C3%AAtre%20r%C3%A9cup%C3%A9rer%20toutes%20les%20listes.%20Voici%20une%20fonction%20de%20d%C3%A9compression%26nbsp%3B%3A%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F%2F%20unzip%2C%20similar%20to%20Python's%20unzip%0Aunzip%20%3D%20Function(%20%7Bdt%7D%2C%20%2F%2F%20data%20table%20previously%20returned%20from%20zip%20(above)%0A%20%7Bresult%2C%20cols%2C%20iCol%2C%20col%2C%20names%2C%20iRow%7D%2C%20%2F%2F%20local%20variables%0A%20cols%20%3D%20dt%20%26lt%3B%26lt%3B%20getcolumnnames%3B%20%2F%2F%20below%2C%20the%20_original%20order_%20col%20gets%20skipped%0A%20result%20%3D%20%7B%7D%3B%20%2F%2F%20assemble%20all%20of%20the%20lists%20and%20matrices%20here%2C%20return%20at%20bottom%0A%20For(%20iCol%20%3D%201%2C%20iCol%20%26lt%3B%20N%20Items(%20cols%20)%2F*skip%20last%20one*%2F%2C%20iCol%20%2B%3D%201%2C%0A%20%20col%20%3D%20Column(%20dt%2C%20cols%5Bicol%5D%20)%3B%20%2F%2F%20the%20Ith%20col%20in%20the%20table%0A%20%20If(%20col%20%26lt%3B%26lt%3B%20getdatatype(%20%22English%22%20)%20%3D%3D%20%22Numeric%22%2C%20%2F%2F%0A%20%20%20%2F%2F%20return%20the%20same%20type%20of%20object%2C%20list%20or%20matrix%2C%20supplied%20originally%0A%20%20%20If(%20col%20%26lt%3B%26lt%3B%20getproperty(%20%22wasMatrix%22%20)%2C%20%2F%2F%20by%20checking%20the%20property%20we%20set%20above%0A%20%20%20%20Insert%20Into(%20result%2C%20col%20%26lt%3B%26lt%3B%20getValues%20)%3B%20%2F%2F%20append%20a%20matrix%0A%20%20%20%2C%20%2F%2F%20else%20append%20a%20list%20of%20numbers%0A%20%20%20%20result%5BN%20Items(%20result%20)%20%2B%201%5D%20%3D%20As%20List(%20dt%5B0%2C%20iCol%5D%20)%0A%20%20%20)%0A%20%20%2C%20%2F%2F%20else%20character%20column%0A%20%20%20%2F%2F%20return%20same%20type%2C%20list%20of%20names%20or%20list%20of%20strings...%0A%20%20%20If(%20col%20%26lt%3B%26lt%3B%20getproperty(%20%22wasString%22%20)%2C%20%2F%2F%20check%20character%20col%20prop%20set%20above%0A%20%20%20%20result%5BN%20Items(%20result%20)%20%2B%201%5D%20%3D%20(dt%5B0%2C%20iCol%5D)%20%2F%2F%20list%20of%20strings%0A%20%20%20%2C%20%2F%2F%20else%20turn%20the%20strings%20into%20names%20again%0A%20%20%20%20result%5BN%20Items(%20result%20)%20%2B%201%5D%20%3D%20As%20Name(%20dt%5B0%2C%20iCol%5D%20)%20%2F%2F%20list%20of%20names%0A%20%20%20)%0A%20%20)%3B%0A%20)%3B%0A%20result%3B%20%2F%2F%20return%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3EExemple%3A%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%7Bcars%2C%20doors%2C%20miles%2C%20owner%7D%20%3D%20unzip(%20zippedDt%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CSTRONG%3EListe%20(4%20%C3%A9l%C3%A9ments)%20assign%C3%A9e.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Evoitures%26nbsp%3B%3A%7Bford%2C%20volkswagon%2C%20chevy%2C%20honda%2C%20toyota%7D%3CBR%20%2F%3E%20portes%26nbsp%3B%3A%5B5%2C%202%2C%204%2C%202%2C%202%5D%3CBR%20%2F%3E%20milles%26nbsp%3B%3A%7B10%26nbsp%3B000%2C%2020%26nbsp%3B000%2C%2030%26nbsp%3B000%2C%2040%26nbsp%3B000%2C%2050%26nbsp%3B000%7D%3CBR%20%2F%3E%20propri%C3%A9taire%26nbsp%3B%3A%7B%22penelope%22%2C%20%22susan%22%2C%20%22fred%22%2C%20%22ralph%22%2C%20%22terry%22%7D%3C%2FP%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3EPour%20terminer%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F%2F%20Important!%20delete%20the%20invisible%20table!%0AClose(%20zippedDt%2C%20nosave%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FDIV%3E%3CDIV%20class%3D%22lia-message-template-solution-zone%22%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EDiscussion%3C%2FSTRONG%3E%3C%2FFONT%3E%3CP%3EAssurez-vous%20de%20nettoyer%20la%20table%20invisible%20si%20vous%20utilisez%20les%20fonctions%20zip%2Funzip.%20(Ils%20ne%20sont%20pas%20li%C3%A9s%20%C3%A0%20la%20fonction%20de%20compression%20des%20fichiers%20.zip.%20JMP%20prend%20en%20charge%20cela%20dans%20l'objet%20d'archive%20zip.)%3C%2FP%3E%3CP%3ELa%20table%20de%20donn%C3%A9es%20est%20un%20excellent%20outil%20pour%20les%20structures%20de%20donn%C3%A9es%20complexes.%20Vous%20pouvez%20cr%C3%A9er%20des%20tables%20masqu%C3%A9es%20ou%20priv%C3%A9es%20pour%20g%C3%A9rer%20les%20donn%C3%A9es%20sans%20utiliser%20les%20fonctions%20wrapper%20ci-dessus.%20Les%20listes%20peuvent%20%C3%AAtre%20plus%20efficaces%20que%20les%20tables%20de%20donn%C3%A9es%20si%20vous%20devez%20ajouter%20et%20supprimer%20un%20grand%20nombre%20d'%C3%A9l%C3%A9ments%20(les%20files%20d'attente%20et%20les%20piles%20peuvent%20%C3%AAtre%20lentes%20si%20elles%20sont%20impl%C3%A9ment%C3%A9es%20comme%20l'ajout%20et%20la%20suppression%20de%20lignes%20d'une%20table.)%20La%20fonction%20zip%20(ci-dessus)%20attend%20une%20liste%20de%3CEM%3E%20des%20noms%3C%2FEM%3E%20.%20UN%3CEM%3E%20Nom%3C%2FEM%3E%20(sans%20guillemets)%20n'est%20pas%20la%20m%C3%AAme%20chose%20qu'un%3CEM%3E%20cha%C3%AEne%20(utilise%20des%20guillemets)%3C%2FEM%3E%20.%20Passer%20une%20liste%20de%20noms%20r%C3%A9duit%20le%20nombre%20de%20fois%20o%C3%B9%20les%20donn%C3%A9es%20sont%20copi%C3%A9es.%3C%2FP%3E%3CBR%20%2F%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EVoir%20%C3%A9galement%3C%2FSTRONG%3E%3C%2FFONT%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2F14-2%2Flist-functions.shtml%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2F14-2%2Flist-functions.shtml%3C%2FA%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Sorting Lists
Problem

You have data in one or more lists or matrix vectors that you need to sort.

Solution

Use Sort List() or Sort List Into(), Rank(), or put the lists and vectors in a data table and sort it.

 

// Sort List example (makes new list)
names = {"fred", "Andy", "Rory", "bess", "susy", "perl"};
sname = Sort List( names );
Show( names, sname );

names = {"fred", "Andy", "Rory", "bess", "susy", "perl"}; // unchanged

sname = {"Andy", "bess", "fred", "perl", "Rory", "susy"}; // sorted
// Sort List Into example (in-place sort)
names = {"fred", "Andy", "Rory", "bess", "susy", "perl"};
Sort List Into( names );
Show( names );
names = {"Andy", "bess", "fred", "perl", "Rory", "susy"}; // sorted in-place
Both examples above operate on a single list. If there is a second list of phone numbers, they don't stick to the names.
To make several lists all have the same sort, you might use the Rank() function. The lists should have the same number of elements and no missing values in the sort-key list.
names = {"fred", "Andy", "Rory", "bess", "susy", "perl"};
phone = {"x321", "x322", "x323", "x324", "x325", "x326"};
rooms = {"1003", "1001", "1005", "1002", "1006", "1004"};

rnk = Rank( names ); // [2, 4, 1, 6, 3, 5]

// use the rnk vector to make sorted lists from the old lists
snames = names[rnk];
sphone = phone[rnk];
srooms = rooms[rnk];

Show( snames, sphone, srooms );
snames = {"Andy", "bess", "fred", "perl", "Rory", "susy"};
sphone = {"x322", "x324", "x321", "x326", "x323", "x325"};
srooms = {"1001", "1002", "1003", "1004", "1005", "1006"};
 
Above, the new lists with the prefix s are all sorted by name.
 
If you have multiple lists, of the same length, but paired across the lists, perhaps a data table would be a better data structure. You might find it easier to use a table because you can see it, save it, subset it, ...  But if you have the lists already, you can build a table from them. Here is a re-usable user function that does that:
// the zip function, named after a Python function that, like a zipper, zips two lists together
zip = Function( {variableNameList}, // a list of variable names
	{iVarName, dt, data}, // local variables
	dt = New Table( "zip", "invisible" ); // a hidden table, returned at end of this function
	For( iVarName = 1, iVarName <= N Items( variableNameList ), iVarName += 1,
		data = Eval( variableNameList[iVarName] ); // makes a copy of the data from the name
		If( Is Matrix( data ) | Is Number( data[1] ), // handle lists of numbers same as a matrix
			dt << New Column( Char( variableNameList[iVarName] ), "numeric", values( data ),
				setProperty( "wasMatrix", eval(Is Matrix( data ) ) ) ) // remember how to convert back, could be list
		, // else a list of strings
			dt << New Column( Char( variableNameList[iVarName] ), "character", values( data ),
				setProperty( "wasString", eval( Is String( data[1] ) ) ) ) // remember how to convert back, could be names
		);
	);
	dt << New Column( "_original order_", values( 1 :: N Rows( dt ) ) ); // this extra column is not required, but might be useful
	dt << setdirty( 0 ); // not required but avoids a "save?" prompt
	dt; // return
);
example:
cars = {chevy, volkswagon, honda, ford, toyota}; // list of unquoted names
doors = [4, 2, 2, 5, 2]; // matrix of numbers
miles = {30000, 20000, 40000, 10000, 50000}; // list of numbers
owner = {"fred", "susan", "ralph", "penelope", "terry"}; // list of quoted strings

zippedDt = zip( {cars, doors, miles, owner} );
zippedDt << sort( by( miles ), replacetable( 1 ) );

zippedDt << show Window; // table hidden by default
Lists are in table's columns, sorted by milesLists are in table's columns, sorted by miles
If you are working with lists, you might want all the lists back again. Here's an unzip function:
// unzip, similar to Python's unzip
unzip = Function( {dt}, // data table previously returned from zip (above)
	{result, cols, iCol, col, names, iRow}, // local variables
	cols = dt << getcolumnnames; // below, the _original order_ col gets skipped
	result = {}; // assemble all of the lists and matrices here, return at bottom
	For( iCol = 1, iCol < N Items( cols )/*skip last one*/, iCol += 1,
		col = Column( dt, cols[icol] ); // the Ith col in the table
		If( col << getdatatype( "English" ) == "Numeric", //
			// return the same type of object, list or matrix, supplied originally
			If( col << getproperty( "wasMatrix" ), // by checking the property we set above
				Insert Into( result, col << getValues ); // append a matrix
			, // else append a list of numbers
				result[N Items( result ) + 1] = As List( dt[0, iCol] )
			)
		, // else character column
			// return same type, list of names or list of strings...
			If( col << getproperty( "wasString" ), // check character col prop set above
				result[N Items( result ) + 1] = (dt[0, iCol]) // list of strings
			, // else turn the strings into names again
				result[N Items( result ) + 1] = As Name( dt[0, iCol] ) // list of names
			)
		);
	);
	result; // return
);
example:
{cars, doors, miles, owner} = unzip( zippedDt );

List( 4 elements ) assigned.

cars:{ford, volkswagon, chevy, honda, toyota}
doors:[5, 2, 4, 2, 2]
miles:{10000, 20000, 30000, 40000, 50000}
owner:{"penelope", "susan", "fred", "ralph", "terry"}

Finally
// Important! delete the invisible table!
Close( zippedDt, nosave );
Discussion

Be sure to clean up the invisible table if you use the zip/unzip functions. (They are unrelated to the compression function for .zip files. JMP has support for that in the zip archive object.)

The data table is a great tool for complicated data structures. You can make hidden or private tables for managing data without using the wrapper functions above. Lists may be more efficient than data tables if you need to add and remove a lot of items (queues and stacks might be slow if implemented as adding and removing rows from a table.) The zip function (above) expects a list of names. A name (no quotation marks) is not the same as a string (uses quotation marks). Passing a list of names reduces the number of times data is copied. 


See Also

https://www.jmp.com/support/help/14-2/list-functions.shtml 

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.