Difference between revisions of "MdArrayToTable"
Line 5: | Line 5: | ||
Transforms a multi-dimensional array, ''A'', into a two-dimensional | Transforms a multi-dimensional array, ''A'', into a two-dimensional | ||
− | array (i.e., a table) indexed by ''I'' and ''L''. The result contains one | + | array (i.e., a relational table) indexed by ''I'' and ''L''. The result contains one |
row along ''I'' for each element of ''A''. ''L'' must contain a list of names | row along ''I'' for each element of ''A''. ''L'' must contain a list of names | ||
of the indexes of ''A'', followed by one final element. All elements of | of the indexes of ''A'', followed by one final element. All elements of | ||
L must be text values. The column corresponding to the final element | L must be text values. The column corresponding to the final element | ||
of ''L'' contains the cell value. If L does not contain all the | of ''L'' contains the cell value. If L does not contain all the | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
indexes of ''A'', array abstraction will create a set of tables indexed | indexes of ''A'', array abstraction will create a set of tables indexed | ||
by the dimensions not listed in ''L''. | by the dimensions not listed in ''L''. | ||
Line 26: | Line 17: | ||
[[MdTable]]( ) on a table that contains a row for only the nonzero | [[MdTable]]( ) on a table that contains a row for only the nonzero | ||
elements of the array. | elements of the array. | ||
+ | |||
+ | == Creating a fact table == | ||
+ | |||
+ | ''New to [[What's new in Analytica 4.2?|Analytica 4.2]]'' | ||
+ | |||
+ | ::[[MdArrayToTable]](A,I,L'',valueIndex'') | ||
+ | |||
+ | A fact table is a generalization of a simple relational table. In a fact table, the first ''N'' columns identify cell coordinates, and the last ''K'' columns hold measured values (often called ''measures'', ''facts'', or just ''values''). This generalized the simple relational table where only the single final row holds a value. | ||
+ | |||
+ | The optional parameter, «valueColumn», specifies an index of «A» that is used for the value columns in the result. The first [[Size]](L) - [[Size]](valueIndex) columns of «L» are then the coordinates, and the final [[Size]](valueIndex]] columns of «L» hold the values. | ||
+ | |||
+ | When omitting cells having no data, all values in «A» along the valueIndex must be zero or null. If any of the values have data, the corresponding cell (i.e., row in the result) is considered to have data. | ||
+ | |||
+ | == Positional Coordinates == | ||
+ | |||
+ | ''New to [[What's new in Analytica 4.2?|Analytica 4.2]]'' | ||
+ | |||
+ | ::[[MdArrayToTable]](...,positional:true) | ||
+ | |||
+ | Normally, the first ''N'' columns of the result specify coordinates using index ''labels''. When the optional parameter «positional» is specified as true, index positions are returned rather than labels. | ||
= Library = | = Library = |
Revision as of 23:23, 20 August 2009
MdArrayToTable(A,I,L)
Transforms a multi-dimensional array, A, into a two-dimensional array (i.e., a relational table) indexed by I and L. The result contains one row along I for each element of A. L must contain a list of names of the indexes of A, followed by one final element. All elements of L must be text values. The column corresponding to the final element of L contains the cell value. If L does not contain all the indexes of A, array abstraction will create a set of tables indexed by the dimensions not listed in L.
If the number of elements in I is equal to the number of nonzero elements of A, MDArrayToTable() acts like the inverse of MdTable( ) on a table that contains a row for only the nonzero elements of the array.
Creating a fact table
New to Analytica 4.2
- MdArrayToTable(A,I,L,valueIndex)
A fact table is a generalization of a simple relational table. In a fact table, the first N columns identify cell coordinates, and the last K columns hold measured values (often called measures, facts, or just values). This generalized the simple relational table where only the single final row holds a value.
The optional parameter, «valueColumn», specifies an index of «A» that is used for the value columns in the result. The first Size(L) - Size(valueIndex) columns of «L» are then the coordinates, and the final Size(valueIndex]] columns of «L» hold the values.
When omitting cells having no data, all values in «A» along the valueIndex must be zero or null. If any of the values have data, the corresponding cell (i.e., row in the result) is considered to have data.
Positional Coordinates
New to Analytica 4.2
- MdArrayToTable(...,positional:true)
Normally, the first N columns of the result specify coordinates using index labels. When the optional parameter «positional» is specified as true, index positions are returned rather than labels.
Library
Array
Example
Define these global objects (as indexes or variables):
Rows := sequence(1,size(Cost_in_time)) Cols := [‘Mpg’,’Time’,’Car_type’,’Cost’]
MDArrayToTable(Cost_in_time,Rows,Cols) →
Mpg | Time | Car_type | Cost | |
---|---|---|---|---|
1 | 26 | 0 | VW | 2185 |
2 | 26 | 0 | Honda | 2385 |
3 | 26 | 0 | BMW | 3185 |
4 | 26 | 1 | VW | 2294 |
5 | 26 | 1 | Honda | 2314 |
6 | 26 | 1 | BMW | 3294 |
7 | 26 | 2 | VW | 2409 |
... | ||||
45 | 35 | 4 | BMW | 5175 |
Note: The expression for doing the same transformation using local indexes looks like
Index Rows := sequence(1,size(Cost_in_time)) Index Cols := [‘Mpg’,’Time’,’Car_type’,’Cost’] MDArrayToTable(Cost_in_time,Rows,Cols)
Enable comment auto-refresher