Difference between revisions of "Creating an index"

(Created page with "Category:Analytica User Guide <languages /> <translate> Analytica User Guide > Creating an index An '''''index '''''is a class of variable used to identify a dime...")
 
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Analytica User Guide]]
 
[[Category:Analytica User Guide]]
<languages />
+
<breadcrumbs>Analytica User Guide > Arrays and Indexes > {{PAGENAME}}</breadcrumbs>
<translate>
 
[[Analytica User Guide]] > [[Creating an 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.
 
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:
 
You create an index much like any other variable:
  
'''Create an index node''':  
+
<div id="Index_node">'''Create an index node''':</div>
# Select the edit tool [[File:Chapter11_48.jpg]] and open a '''Diagram '''window.
+
<ol><li> Select the edit tool [[File:Chapter11_48.jpg]] and open a [[Diagram window]].</li>
# Drag the parallelogram shape [[File:Chapter11_49.jpg]] from the node palette to the diagram.
+
<li> Drag the parallelogram shape [[File:Chapter11_49.jpg]] from the node palette to the diagram.</li>
# Type a title into the new index node.
+
<li> Type a title into the new index node.</li>
# Open the definition attribute for the new index:
+
<li> Open the definition attribute for the new index:
* Either double-click the index node to open its '''Object '''window
+
* 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.
+
* Or, select the index node, open the [[Attribute panel]] and select '''Definition''' from the '''Attribute '''menu.</li>
# Press the '''''expr '''''menu above the definition field, to see these options.<br />[[File:Chapter11_50.jpg]] <br /> (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.)
+
<li> Press the [[expr]] menu above the definition field, to see these options.<br />
# 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.<br />[[File:Chapter11_51.jpg]]
+
[[File:Chapter11_50.jpg]] <br />
# Click the cell to select it, and Type in a number for '''List '''or text for '''List of Labels'''.
+
(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.)</li>
# Press ''Enter ''or ''down-arrow ''to add a cell for the next item. Type in its value.
+
<li> 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.<br />[[File:Chapter11_51.jpg]]</li>
# Repeat until you have entered all the values you want.
+
<li> Click the cell to select it, and Type in a number for '''List '''or text for '''List of Labels'''.</li>
 
+
<li> Press ''Enter ''or ''down-arrow ''to add a cell for the next item. Type in its value.</li>
[[File:Chapter11_52.jpg]]
+
<li> Repeat until you have entered all the values you want.<br />
 +
[[File:Chapter11_52.jpg]]</li></ol>
  
 
'''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.
 
'''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.
Line 27: Line 27:
 
'''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 [[File:Chapter11_53.jpg]] from the toolbar to show the '''expression view'''. For example, here is a list of numbers in each view.
 
'''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 [[File:Chapter11_53.jpg]] from the toolbar to show the '''expression view'''. For example, here is a list of numbers in each view.
  
[[File:Chapter11_54.jpg]]
+
:[[File: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.
 
'''List of labels''': In a list of labels, every value is text. In the expression view, each label is enclosed in single quotation marks.
  
[[File:Chapter11_55.jpg]]
+
:[[File: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:
 
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:
Line 39: Line 39:
 
'''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.
 
'''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.
  
[[File:Chapter11_56.jpg]]
+
:[[File: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.
 
If you attempt to mix numbers and text in a list of labels, all the values are treated as text, as shown below.
  
[[File:Chapter11_57.jpg]]
+
:[[File:Chapter11_57.jpg]]
  
 
<tip title="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.</tip>
 
<tip title="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.</tip>
Line 50: Line 50:
 
You can edit a list by changing, adding, or deleting '''''cells '''''(list items).
 
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.  
+
'''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 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.
+
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:
 
'''Delete a cell''': To delete one or more contiguous cells, select them and:
* Choose '''Delete Rows '''from the '''Edit '''menu.
+
* Choose '''Delete Rows '''from the [[Edit menu]].
 
* Or, just press ''Control+k ''or ''Backspace''.
 
* Or, just press ''Control+k ''or ''Backspace''.
  
Line 65: Line 65:
  
 
== Defining an index as a sequence ==
 
== 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''').
+
'''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''').
  
[[File:Chapter11_58.jpg]]
+
:[[File:Chapter11_58.jpg]]
  
Then it shows the Sequence() function in the '''Object Finder.
+
Then it shows the [[Sequence]] function in the [[Object Finder dialog]].
  
[[File:Chapter11_59.jpg]]
+
:[[File:Chapter11_59.jpg]]
  
 
After entering the '''Start''', '''End''', and '''Stepsize '''values, click '''OK'''<nowiki>; the definition field</nowiki> shows the '''Sequence '''button with its parameters.
 
After entering the '''Start''', '''End''', and '''Stepsize '''values, click '''OK'''<nowiki>; the definition field</nowiki> shows the '''Sequence '''button with its parameters.
  
[[File:Chapter11_60.jpg]]
+
:[[File:Chapter11_60.jpg]]
  
 
<tip title="Tip">To change the start, end, or stepsize parameters of a sequence, click the '''Sequence '''button.</tip>
 
<tip title="Tip">To change the start, end, or stepsize parameters of a sequence, click the '''Sequence '''button.</tip>
  
To define an index as a sequence of successive integers, you can use the “'''..'''” operator in the expression view, for example:
+
To define an index as a sequence of successive integers, you can use the [[Sequence Operator|Sequence]] operator “'''..'''” in the expression view, for example:
  
 
:<code>Index Year := 2000 .. 2012</code>
 
:<code>Index Year := 2000 .. 2012</code>
  
 
==See Also==
 
==See Also==
{| style="margin: 1em auto 1em auto;width: 100%;border:0;table-layout: fixed;" cellpadding=5
+
* [[Tutorial: Arrays#Creating_an_index_variable|Tutorial: Creating an index variable]]
|- style="text-align: center"
+
* [[Tutorial: Arrays]]
| [[IF a THEN b ELSE c with arrays]] <- || [[Creating an index]] || -> [[Functions that create indexes]]
+
* [[Local Indexes]]
|}
+
* [[Expressions]]
</translate>
+
* [[Expression Assist]]
 +
* [[Index..Do]]
 +
 
 +
 
 +
<footer>IF a THEN b ELSE c with arrays / {{PAGENAME}} / Functions that create indexes</footer>

Latest revision as of 23:04, 11 August 2016

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.