Loc( list, value );
Contains( list, value );
Loc() and Contains() return the positions of the values. Loc() returns the results in a matrix, and Contains() returns the results as a number.
•
|
The Loc function returns each occurrence of a repeated value. Contains() returns only the first occurrence of a repeated value.
|
•
|
•
|
To assess whether an item is in a list, use Loc() and Contains() with >0. A returned value of zero means that the item is not in the list. A returned value of 1 means that the item is in the list at least once.
|
Note: For details about matrix manipulation and a description of the equivalent Loc() command for matrices, see Matrices.
nameList = {"Katie", "Louise", "Jane", "Jane"};
numList = {2, 4, 6, 8, 8};
Loc( nameList, "Katie" );
[1]
Contains( nameList, "Katie" );
1
Loc( nameList, "Erin" );
[]
Contains( nameList, "Erin" );
0
Loc( numList, 8 );
[4, 5]
Contains( numList, 8 );
4
NRow( Loc( numList, 5 ) ) > 0;
0
Contains( numList, 5 ) > 0;
0