cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-444727%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EComment%20obtenir%20l'index%20d'une%20valeur%2Fentr%C3%A9e%20particuli%C3%A8re%20dans%20une%20liste%26nbsp%3B%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-444727%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJ'ai%20la%20liste%20suivante%2C%20comment%20puis-je%20obtenir%20l'index%20de%20SplPparameter%26nbsp%3B%3F%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EmyList%20%3D%20%7Bparamter1%2C%20parameter2%2C%20parameter3%2C%20Splparameter%2C%20parameterN%2C%20parameterEnd%7D%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EAns%20est%204%20dans%20l'exemple%20ci-dessus.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-444727%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3EMod%C3%A9lisation%20statistique%20avanc%C3%A9e%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIng%C3%A9nierie%20de%20la%20qualit%C3%A9%20et%20des%20proc%C3%A9d%C3%A9s%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-444944%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20Comment%20obtenir%20l'index%20d'une%20valeur%2Fentr%C3%A9e%20particuli%C3%A8re%20dans%20une%20liste%26nbsp%3B%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-444944%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESi%20vous%20savez%20que%20les%20%C3%A9l%C3%A9ments%20sont%20des%20expressions%2C%20alors%20ce%20code%20plus%20court%20fonctionnera.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%2F%2F%20My%20solution%20when%20list%20items%20are%20expressions%0AmyList%20%3D%20%7Bparamter1%2C%20parameter2%2C%20parameter3%2C%20Splparameter%2C%20parameterN%2C%20parameterEnd%7D%3B%0AContains(%20myList%2C%20Expr(%20Splparameter%20)%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESinon%2C%20vous%20avez%20besoin%20d'un%20code%20plus%20g%C3%A9n%C3%A9ral%20comme%20celui%20fourni%20par%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2687%22%20target%3D%22_blank%22%3E%20%40txnelson%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-444803%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20Comment%20obtenir%20l'index%20d'une%20valeur%2Fentr%C3%A9e%20particuli%C3%A8re%20dans%20une%20liste%26nbsp%3B%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-444803%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EDans%20le%20cas%20d'expressions%2C%20vous%20pouvez%20%C3%A9galement%20utiliser%20'Loc()'%20(qui%20renvoie%20un%20vecteur%20colonne)%26nbsp%3B%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%0AmyList%20%3D%20%7Bparamter1%2C%20parameter2%2C%20parameter3%2C%20Splparameter%2C%20parameterN%2C%20parameterEnd%2C%20Splparameter%7D%3B%0APrint(loc(mylist%2C%20Expr(Splparameter)))%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-444780%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20Comment%20obtenir%20l'index%20d'une%20valeur%2Fentr%C3%A9e%20particuli%C3%A8re%20dans%20une%20liste%26nbsp%3B%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-444780%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CSTRONG%3EVoici%20quelques%20fa%C3%A7ons%20de%20traiter%20votre%20question.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%2F%2F%20My%20solution%20when%20list%20items%20are%20expressions%0AmyList%20%3D%20%7Bparamter1%2C%20parameter2%2C%20parameter3%2C%20Splparameter%2C%20parameterN%2C%20parameterEnd%7D%3B%0A%0AFor(%20i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Items(%20mylist%20)%2C%20i%2B%2B%2C%0A%20If(%20myList%5Bi%5D%20%3D%3D%20Parse(%20%22Splparameter%22%20)%2C%0A%20%20Break()%0A%20)%0A)%3B%0AShow(%20i%20)%3B%0A%0A%2F%2F%20If%20elements%20are%20strings%20the%20contains%20can%20be%20used%0AmyList%20%3D%20%7B%22paramter1%22%2C%20%22parameter2%22%2C%20%22parameter3%22%2C%20%22Splparameter%22%2C%20%22parameterN%22%2C%20%22parameterEnd%22%7D%3B%0Ai%20%3D%20Contains(%20myList%2C%20%22Splparameter%22%20)%3B%0A%0A%2F%2F%20%20Same%20using%20Loc()%20function%0Ai%20%3D%20loc(mylist%2C%22Splparameter%22%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Neo
Neo
Level VI

How to get the index of a particular value/entry in a list?

I have the following list, how do I get the index of SplPparameter?

myList = {paramter1, parameter2, parameter3, Splparameter, parameterN, parameterEnd};

Ans is 4  in the above example. 

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to get the index of a particular value/entry in a list?

Here are a couple of ways to handle your question.

Names Default To Here( 1 );
// My solution when list items are expressions
myList = {paramter1, parameter2, parameter3, Splparameter, parameterN, parameterEnd};

For( i = 1, i <= N Items( mylist ), i++,
	If( myList[i] == Parse( "Splparameter" ),
		Break()
	)
);
Show( i );

// If elements are strings the contains can be used
myList = {"paramter1", "parameter2", "parameter3", "Splparameter", "parameterN", "parameterEnd"};
i = Contains( myList, "Splparameter" );

//  Same using Loc() function
i = loc(mylist,"Splparameter" );
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How to get the index of a particular value/entry in a list?

Here are a couple of ways to handle your question.

Names Default To Here( 1 );
// My solution when list items are expressions
myList = {paramter1, parameter2, parameter3, Splparameter, parameterN, parameterEnd};

For( i = 1, i <= N Items( mylist ), i++,
	If( myList[i] == Parse( "Splparameter" ),
		Break()
	)
);
Show( i );

// If elements are strings the contains can be used
myList = {"paramter1", "parameter2", "parameter3", "Splparameter", "parameterN", "parameterEnd"};
i = Contains( myList, "Splparameter" );

//  Same using Loc() function
i = loc(mylist,"Splparameter" );
Jim
ian_jmp
Level X

Re: How to get the index of a particular value/entry in a list?

In the case of expressions, you can also use 'Loc()' (which returns a column vector):

Names Default To Here( 1 );

myList = {paramter1, parameter2, parameter3, Splparameter, parameterN, parameterEnd, Splparameter};
Print(loc(mylist, Expr(Splparameter)));

Re: How to get the index of a particular value/entry in a list?

If you know that the items are expressions, then this shorter code will work.

 

Names Default To Here( 1 );
// My solution when list items are expressions
myList = {paramter1, parameter2, parameter3, Splparameter, parameterN, parameterEnd};
Contains( myList, Expr( Splparameter ) );

 

If not, then you need a more general code like the one provided by @txnelson 

Recommended Articles