Difference between revisions of "MdTable"

 
(Copy/pasted from user guide)
Line 1: Line 1:
[[category:Array Functions]]
+
[[category:Array Flattening Functions]]
  
{{stub}}
+
= 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".
 +
 
 +
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:
 +
 
 +
{| border="1"
 +
|+ Rows v,  Cols >>
 +
! !! 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’) -->
 +
 
 +
{| border="1"
 +
|+ Rows v,  Cols >>
 +
! !! 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.

Revision as of 22:46, 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".

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:

Rows v, Cols >>
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’) -->
Rows v, Cols >>
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.

Comments


You are not allowed to post comments.