•
|
•
|
•
|
use the List function
|
•
|
Use the List() function or curly braces to create a list that includes numbers and variables:
To evaluate items in a list, use the Eval List function.
Consider the following example, where you have a variable called fullMonth that is a list of 12 items.
When you add the Eval function:
In a loop, you need the Eval function in the nested loop to evaluate the variable’s contents. For example:
To determine the number of items in a list, use the N Items() function.
List a contains four items.
•
|
Multiple left-side subscripts (for example, a[i][j] = value where a contains a list of things that are subscriptable) are allowed in the following circumstances:
|
‒
|
Each level except the outermost level must be a list. So, in the example above, a must be a list but a[i] can be anything subscriptable.
|
‒
|
Each subscript except the last must be a number. So, in the example above, i must be a number, but j could be a matrix or list of indices.
|
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.
List Operators describes the list operators and their syntax.
As List()
|
As List(matrix)
|
||||||
Assign()
Add To()
DivideTo()
|
|
||||||
Eval List(list)
|
|||||||
Inserts a new item (x) into the list at the given position (i). If i is not given, the item is added to the end of the list. This function does change the original list.
|
|||||||
Insert()
|
Returns a copy of the list with a new item (x) inserted into the list at the given position (i). If i is not given, the item is added to the end of the list. This function does not change the original list.
|
||||||
Is List()
|
Is List(arg)
|
Returns true (1) if arg is a classical list (in other words, one that would result from the construction by List(items) or {items}) and returns false (0) otherwise. An empty list is still a list, so IsList({ }) returns true. If miss=., then IsList(miss) returns false, not missing.
|
|||||
Constructs a list from a set of items. An item can be any expression, including other lists. Items must be separated by commas. Text should either be enclosed in double quotation marks ( " " ) or stored in a variable and called as that variable.
|
|||||||
N Items(list)
|
Returns the number of elements in the list specified. Can be assigned to a variable.
|
||||||
Deletes n items from the list, starting from the indicated position (i). If n is omitted, the item at i is deleted. If n and i are omitted, the item at the end is removed. This function does change the original list.
|
|||||||
Remove()
|
Returns a copy of the list with the n items deleted, starting from the indicated position (i). If n is omitted, the item at i is deleted. If n and i are omitted, the item at the end is removed. This function does not change the original list.
|
||||||
Reverse Into(list)
|
Reverses the order of the items in the list. This function does change the original list.
|
||||||
Reverse()
|
Reverse(list)
|
Returns a copy of the list with the items in reverse order. This function does not change the original list.
|
|||||
Shifts n items from the front of the list to the end of the list. If n is omitted, the first item is moved to the end of the list. This function does change the original list.
|
|||||||
Shift()
|
Returns a copy of the list with n items shifted from the front of the list to the end of the list. If n is omitted, the first item is moved to the end of the list. This function does not change the original list.
|
||||||
Sort Ascending(list)
|
Returns a copy of the list sorted in ascending order. This function does not change the original list.
|
||||||
Sort Descending(list)
|
Returns a copy of the list sorted in descending order. This function does not change the original list.
|
||||||
Sort List Into(list)
|
Sorts the list in ascending order. This function does change the original list.
|
||||||
Sort List(list)
|
Returns a copy of the list sorted in ascending order. This function does not change the original list.
|
||||||
list[i]
|
Subscripts for lists extract the ith item from the list. Subscripts can in turn be lists or matrices.
|
||||||
Changes a list or expression, replacing instances of each pattern expression with the corresponding replacement expression. Note: The list or expression must be a variable.
|
You can use Loc() to locate the items in the new list that are equal to 25:
The following example joins the same lists using the || operator: