====== Table Type ======
A table is a collection of [[wp>Tuple|tuples]] organized in a special way, where each tuple may be formed by several keys and values. The set of keys in each row must be unique.
[{{ :editors:table_basics_1.png?nolink |Table Basics}}]
[{{ :editors:table_basics_2.png?nolink |Table Basics}}]
The set of all elements at the same position in all rows defines a column. All columns must have a unique name. The names must follow the general name convention in Dinamica EGO, they must start with a "_" or a letter and must be formed by letters, numbers and underscores. Blanks in names are automatically replaced by "_" (underscore).
Keys and values can be represented using double precision [[wp>Floating_point|floating point numbers]], allowing the definition of integral and fractional values, or [[wp>String_(computer_science)|strings]].
Internally, tables are represented using trees.
> **Tip:** The Dinamica documentation and error messages usually express a table format as a sequence of column names/types separated by commas. For example, the sequence "City_Id*#real, City_Population#real, City_Name#string" corresponds to a table with one key column and two value/data columns. The key column is named "City_Id" with type Real Value Type, and the data/value columns are named "City_Population" and "City_Name" with types Real Value Type and String Type, respectively. It is also possible to omit the column names and represent that table format as "*#real, #real, #string".
>
> When stored as [[wp>Comma-separated_values]] files, tables may also use the column name/type syntax to represent the column attributes — the name, the indication whether it is key or data/value column, and its data type.
===== GUI Editor =====
[{{ :editors:table_editor.png?nolink |Graphical representation of the table editor}}]
It is possible to load the editor content importing the value from a [[wp>Comma-separated_values|CSV file]]. It is also possible to export the content to a [[wp>Comma-separated_values|CSV file]].
===== EGO Script =====
Tables are sequences of elements enclosed by [ ]. The first line of the sequence specifies the column names; every line after that is a row of key/value data, using real values or strings. See [[lookup_table_type|Lookup Table Type]] for lookup tables, a specialized, Real-only case of this same syntax with additional range-generation shorthand.
Each column name has up to three parts, always in this order:
^ Part ^ Required? ^ Meaning ^
| Name | Yes | The column's name, following Dinamica EGO's general naming convention (see above). |
| ''*'' | No | Marks the column as a key column. A column without it is a value/data column. |
| ''#type'' | No — except for empty tables, where it is required unless the type is Real | Explicitly sets the column's type, overriding inference. The only valid values are ''#real'' and ''#string''. |
For example, ''"From*"'' names a key column ''From'' with no explicit type, left to inference, and ''"Variable_Name*#string"'' names a key column ''Variable_Name'' explicitly typed as String.
[
"From*", "To*", "Rate",
1, 2, 0.4,
1, 4, 0.2,
2, 7, 0.5,
4, 8, 0.2
]
Here ''From'' and ''To'' are key columns (marked with ''*''), and ''Rate'' is a value column; none specify a type, so all three are inferred as Real from their data.
The type of each column is inferred by inspecting the column's values: a column is inferred as Real if every value parses as a number, and as String otherwise — inference has no preference toward either type, it is driven entirely by the data. Elements representing strings can be surrounded by double quotes '"'. This inference is what the ''#type'' suffix above overrides — for example, appending ''#string'' to a column name forces it to be read as a string even when its values look like numbers, such as an identifier column where a value like "007" should not collapse to 7.
[
"Categories*", "Name", "Color_Red", "Color_Green", "Color_Blue",
1, "soy", 20, 45, 125,
2, "rice", 20, 100, 125,
7, "coffee", 200, 45, 125,
12, "sugar_cane", 75, 45, 123,
34, "bean", 20, 45, 57,
]
The table below represents the table above without the use of double quotes.
[
Categories*, Name, Color_Red, Color_Green, Color_Blue,
1, soy, 20, 45, 125,
2, rice, 20, 100, 125,
7, coffee, 200, 45, 125,
12, sugar_cane, 75, 45, 123,
34, bean, 20, 45, 57,
]
For an empty table, there is no data to infer a type from, so every column's type must be stated explicitly with a ''#type'' suffix — except Real, which remains the implicit default even with no data present, and so can still be omitted.
[
"From*#real", "To*#real", "Variable_Name*#string", "Upper_Range*#real", "Weight_Coefficient#real"
]
Since ''#real'' is the default, the table above can be written more compactly by omitting it wherever it appears, leaving only the one genuinely necessary ''#string'' annotation:
[
"From*", "To*", "Variable_Name*#string", "Upper_Range*", "Weight_Coefficient"
]
===== Automatic Conversions =====
* **Converted from**: [[Change Matrix Type]], [[Transition Matrix Type]], [[Transition Function Parameter Matrix Type]], [[Percent Matrix Type]], [[Categorization Type]] and [[Lookup Table Type]].
* **Converted to**: [[Change Matrix Type]], [[Transition Matrix Type]], [[Transition Function Parameter Matrix Type]], [[Percent Matrix Type]], [[Categorization Type]] and [[Lookup Table Type]] (only if the table has exactly the columns ''*#real'' and ''#real'').