Difference between revisions of "MdTable"
(Copy/pasted from user guide) |
(adorned with links, italics) |
||
Line 5: | Line 5: | ||
Returns a multi-dimensional array from a two-dimensional table | Returns a multi-dimensional array from a two-dimensional table | ||
of values. T is a two-dimensional array (i.e., a table) indexed by | of values. T is a two-dimensional array (i.e., a table) indexed by | ||
− | Rows and Cols. Each row of T specifies the coordinates of a cell | + | ''Rows'' and ''Cols''. Each row of ''T'' specifies the coordinates of a cell |
in a multi-dimensional array, along with the value for that cell. | in a multi-dimensional array, along with the value for that cell. | ||
Line 15: | Line 15: | ||
If Vars is omitted, the dimensions of the final result are specified | If Vars is omitted, the dimensions of the final result are specified | ||
− | by the first n-1 elements of Cols (n=size(Cols)). In this case, the | + | by the first ''n-1'' elements of ''Cols'' (''n=size(Cols)''). In this case, the |
elements of Cols must be index identifiers or index names. | elements of Cols must be index identifiers or index names. | ||
− | The first n-1 columns of T specify the coordinates of a cell in the | + | The first ''n-1'' columns of ''T'' specify the coordinates of a cell in the |
− | result. The final column of T specifies the value for the indicated | + | result. The final column of ''T'' specifies the value for the indicated |
cell. | cell. | ||
− | Before using MDTable, you must define all of the indexes for the | + | Before using ''MDTable'', you must define all of the indexes for the |
result. Each index must include all values that occur in the corresponding | result. Each index must include all values that occur in the corresponding | ||
− | column of T or an error will result. The Unique() function | + | column of ''T'' or an error will result. The [[Unique]]() function |
is useful for defining the necessary indexes. | is useful for defining the necessary indexes. | ||
− | It is possible that two or more rows of T specify identical coordinates. | + | It is possible that two or more rows of ''T'' specify identical coordinates. |
In this case, a conglomeration function is used combine | In this case, a conglomeration function is used combine | ||
the values for the given cell. The conglomFn parameter is a text | the values for the given cell. The conglomFn parameter is a text | ||
Line 33: | Line 33: | ||
Possible values are: "sum" (default), "min", "max", "average", or | Possible values are: "sum" (default), "min", "max", "average", or | ||
"product". | "product". | ||
+ | |||
+ | (new to 4.0 -- to fill in): Using your own UDF-defined conglomeration functions. | ||
It is also possible that no row in T corresponds to a particular cell. | It is also possible that no row in T corresponds to a particular cell. | ||
Line 45: | Line 47: | ||
= Example = | = Example = | ||
− | Suppose T, Rows, and Cols are defined as indicated by the following | + | Suppose ''T'', ''Rows'', and ''Cols'' are defined as indicated by the following |
table: | table: | ||
Line 67: | Line 69: | ||
|} | |} | ||
− | MDTable(T,Rows,Cols,[Car_type,Mpg], | + | MDTable(T,Rows,Cols,[Car_type,Mpg],'average','n/a') --> |
{| border="1" | {| border="1" | ||
Line 81: | Line 83: | ||
Notice that in the example, Rows 6 and 7 both specified values | Notice that in the example, Rows 6 and 7 both specified values | ||
− | for Car_type=BMW, Mpg=35. The | + | for ''Car_type=BMW, Mpg=35''. The "average" conglomeration function |
was used to combine these. | was used to combine these. | ||
+ | |||
+ | = See Also = | ||
+ | |||
+ | * [[Unique]] | ||
+ | * [[MdArrayToTable]] |
Revision as of 22:50, 2 February 2007
MdTable(T,Rows,Cols,Vars,conglomFn,missingval)
Returns a multi-dimensional array from a two-dimensional table of values. T is a two-dimensional array (i.e., a table) indexed by Rows and Cols. Each row of T specifies the coordinates of a cell in a multi-dimensional array, along with the value for that cell.
The dimensions of the final result are given by the optional
parameter Vars. Vars must be a list of index identifiers or index
names. The length of Cols must be one greater than the length of
Vars.
If Vars is omitted, the dimensions of the final result are specified by the first n-1 elements of Cols (n=size(Cols)). In this case, the elements of Cols must be index identifiers or index names.
The first n-1 columns of T specify the coordinates of a cell in the result. The final column of T specifies the value for the indicated cell.
Before using MDTable, you must define all of the indexes for the result. Each index must include all values that occur in the corresponding column of T or an error will result. The Unique() function is useful for defining the necessary indexes.
It is possible that two or more rows of T specify identical coordinates. In this case, a conglomeration function is used combine the values for the given cell. The conglomFn parameter is a text value specifying which conglomeration function is to be used. Possible values are: "sum" (default), "min", "max", "average", or "product".
(new to 4.0 -- to fill in): Using your own UDF-defined conglomeration functions.
It is also possible that no row in T corresponds to a particular cell. In this case, the cell value is set to missingval, or if the missingval parameter is omitted, the cell value is set to undefined. Undefined values can be detected using the IsUndef() function.
Library
Array
Example
Suppose T, Rows, and Cols are defined as indicated by the following table:
Car_type | Mpg | X | |
---|---|---|---|
1 | VW | 26 | 2185 |
2 | VW | 30 | 1705 |
3 | Honda | 26 | 2330 |
4 | Honda | 35 | 2210 |
5 | BMW | 30 | 2955 |
6 | BMW | 35 | 2800 |
7 | BMW | 35 | 2870 |
MDTable(T,Rows,Cols,[Car_type,Mpg],'average','n/a') -->
Car_type | Mpg | X | |
---|---|---|---|
VW | 2185 | 1705 | n/a |
Honda | 2330 | n/a | 2210 |
BMW | n/a | 2955 | 2835 |
Notice that in the example, Rows 6 and 7 both specified values for Car_type=BMW, Mpg=35. The "average" conglomeration function was used to combine these.
Enable comment auto-refresher