Creating an index

(Redirected from Index)

How to create an index

An index is a class of variable used to identify a dimension of an array. The same index can identify the same dimension shared by many arrays. Sometimes, variables of other classes, such as a decision, can also be used as an index to identify a dimension of an array. For clarity, use an index variable whenever possible.

You create an index much like any other variable:

Create an index node:
  1. Select the edit tool Chapter11 48.jpg and open a Diagram window.
  2. Drag the parallelogram shape Chapter11 49.jpg from the node palette to the diagram.
  3. Type a title into the new index node.
  4. Open the definition attribute for the new index:
    • Either double-click the index node to open its Object window
    • Or, select the index node, open the Attribute panel and select Definition from the Attribute menu.
  5. Press the expr menu above the definition field, to see these options.
    Chapter11 50.jpg
    (If the variable already has a definition, Analytica confirms that you wish to replace it. Click OK to replace the definition with a one-element list.)
  6. Select List (of numbers) or List of Labels according to whether you want to enter a list of numbers or text values. It will display a list with one item in the definition field.
    Chapter11 51.jpg
  7. Click the cell to select it, and Type in a number for List or text for List of Labels.
  8. Press Enter or down-arrow to add a cell for the next item. Type in its value.
  9. Repeat until you have entered all the values you want.
    Chapter11 52.jpg

Autofill a list: It gives the first cell of a list the default value of 1 (or the previous definition if it had one). When you press Enter or down-arrow, it adds a cell adding 1, or the increment between the two preceding cells, to the value of the preceding cell.

Expression view: You can display a list or list of labels as a list view, the default view showing as a column of cells, or as an expression view, showing it as a list of items between square brackets. Select Chapter11 53.jpg from the toolbar to show the expression view. For example, here is a list of numbers in each view.

Chapter11 54.jpg

List of labels: In a list of labels, every value is text. In the expression view, each label is enclosed in single quotation marks.

Chapter11 55.jpg

To include a single quote (apostrophe) as part of the text in a label in expression view, insert two adjacent single quotes, or enclose in double quotes:

['cant','wont','didnt']

Mixing numbers and text: A list can include a mix of text and numbers. In both views the text is contained in single quotation marks as shown below.

Chapter11 56.jpg

If you attempt to mix numbers and text in a list of labels, all the values are treated as text, as shown below.

Chapter11 57.jpg
Tip
A list cell can contain any valid expression, including one that refers to other variables or one that evaluates to an array. If you are defining an index object, whose sole purpose should be to serve as an index and not as an array result, then each element should evaluate to a scalar; otherwise, a warning will result. For general variables, the use of expressions that return array results is often very useful.

Editing a list

You can edit a list by changing, adding, or deleting cells (list items).

Insert a cell: To insert a cell anywhere other than at the end of the list, select a cell and choose Insert Rows (Control+i) from the Edit menu. The value in the selected cell is duplicated in the new cell.

To add a cell at the end of the list, select the last cell and press Enter or the down-arrow key.

To insert several contiguous cells in the middle of the list, select the number of cells you want to insert and choose Insert Rows (Control+i) from the Edit menu. It duplicates the value of the last selected cell as the default for the new cells.

Delete a cell: To delete one or more contiguous cells, select them and:

  • Choose Delete Rows from the Edit menu.
  • Or, just press Control+k or Backspace.
Tip
If you add or delete a cell in a list that is an index of one or more edit tables, it will warn you that it will change the corresponding slices of the tables.

Navigating a list: Use the up and down-arrow keys to move the cursor up and down the list, or simply click the cell you want.

Defining an index as a sequence

Create a list with the Sequence option: To define an index as a list of equally spaced numbers, it is usually easier to select the Sequence function from the expr menu (instead of List).

Chapter11 58.jpg

Then it shows the Sequence function in the Object Finder dialog.

Chapter11 59.jpg

After entering the Start, End, and Stepsize values, click OK; the definition field shows the Sequence button with its parameters.

Chapter11 60.jpg
Tip
To change the start, end, or stepsize parameters of a sequence, click the Sequence button.

To define an index as a sequence of successive integers, you can use the Sequence operator “..” in the expression view, for example:

Index Year := 2000 .. 2012

See Also


Comments


You are not allowed to post comments.