Functions that create indexes
Using a function to create an index
It is usually easiest to define an index as a list, list of labels, or sequence. Sometimes, you need to define an index using a more general expression, as a list of expressions, a list of variables, or a function such as Subset(), Concat(), and SortIndex(). This section describes these and other functions that you can use to create indexes.
[u1, u2, u3, … um]
A simple way to define an index is specify its definition as a list of values separated by commas and surrounded by square brackets. The values can be numbers, text values, or other expressions.
Examples
[8000, 12K, 15K]
['VW', 'Honda', 'BMW']
These lists are equivalent to using the List or List of Labels options in the expr menu.
List of variables
A list of variables contains identifiers of variables in square brackets, separated by commas. Usually, the simplest way to create a list of variables is to define the variable initially as an empty list, for example:
Variable CompareVars := []
When you draw an arrow from a variable, A
, into CompareVars
, it will automatically add A
as the next item in the list:
CompareVars := [A]
Suppose you draw arrows from B
and C
, the definition will become:
CompareVars := [A, B, C]
When you draw an arrow from a variable already in the list, it removes it from the list. Suppose we draw an arrow from B
to CompareVars
, it will become:
CompareVars := [A, C]
The result of CompareVars
is an array of the values of the variables it contains, with a self index, also called CompareVars
, that usually shows the titles of the variables.
If any or all the variables contain arrays, the result contains the union of the indexes of the contained variables. For example if A is an atom (not an array) and C is indexed by c, the result will be indexed by I. The slice of CompareVars
for A will have the same value of A repeated for each value of A.
Self index: The result will contain an extra index, a Self index of CompareVars
, comprising the list of the variables.
Clickable titles or identifiers in table: Usually these display the titles of the variables in a table or graph result. (If you select Show by Identifier from the Object menu (or press Control+y) it toggles to show the identifiers instead of titles. If you double-click a title (or identifier) in a table, it will open the Object window for that variable. The values in the self index are actually handles to the variables.
m .. n
Returns a sequence of successive integers from «m» to «n» — increasing if «n» < «m», or decreasing if «n» > «m». For example:
2003..2006 → [2003, 2004, 2005, 2006]
5 .. 1 → [5, 4, 3, 2, 1]
It is equivalent to Sequence(m, n).
Other functions
Sequence(start, end, step): Creates a list of numbers from «start» to «end» by increments of «step». See also Sequence().
Concat(i, j): Concatenates two arrays or lists (1-D arrays) «i» and «j» to create a new array or list with a longer index. See also Concat().
Subset(d): Returns a list containing all the elements of «d»’s index for which «d»’s values are true. See also Subset().
CopyIndex(i): Makes a copy of the values of index «i» so that they can be assigned to a new / separate index variable. See also CopyIndex().
SortIndex(d, i): returns the elements of index «i», reordered so that the corresponding values in array «d» go from smallest to largest value. See also SortIndex().
Unique(a, i): Returns a maximal subset of index «i» such that each indicated slice of array «a» along «i» is unique. See also Unique().
See Also
- Function calls and parameters
- Array-reducing functions
- Array functions
- Creating Arrays (Tables)
- Tutorial: Arrays
Enable comment auto-refresher