Functions that create indexes

Revision as of 13:28, 24 September 2015 by DKontotasiou (talk | contribs)


Analytica User Guide > Functions that create indexes

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 con- tained 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).

<tip title="Tip">The parameters n and m must be atoms, that is single numbers. Otherwise, it would result in a non-rectangular array.

Sequence(start, end, stepSize, strict, dateUnit)

Creates a list of numbers increasing or decreasing from start to end by increments (or decrements) of stepSize, which is optional and defaults to 1. When the strict parameter is omitted or false, stepSize must be a positive number and the sequence will decrement by stepSize when end is less than start, guaranteeing at least one element. When strict is specified as true, a positive stepSize increments and negative stepSize returns a decrementing sequence, possibly with zero elements if end would come before start.

The optional dateUnit parameter is used when creating a sequence of dates, with increments in units of Years (dateUnit:'Y'), Months ('M'), Days ('D' or omitted), Weekdays ('WD'<7code>), Hours ('h'), minutes ('m') or seconds ('s').

All parameters must be deterministic scalar numbers, not arrays.

You can also select this function using the Sequence option from the expr menu.

The expression m .. n using the operator ".." is equivalent to Sequence(m, n, 1).


See Also

Creating an index <- Functions that create indexes -> Defining a variable as an edit table
Comments


You are not allowed to post comments.