# Table as Matrix

The special case is the table having all columns of same type; we call it a matrix table and there is a specific type `MatrixTable<'v>` which inherits from the `Table` and allows efficiently get values both by rows and columns, and extend the table in both directions.

To create a matrix table, use `Table.OfMatrix` and provide the matrix as a sequence of rows:

 ```1: ``` ``````let tableMatrix = Table.OfMatrix [| [|11;12;13|]; [|21;22;23|] |] ``````
 ``seq [A[2]: int seq [11; 21]; B[2]: int seq [12; 22]; C[2]: int seq [13; 23]]``

Additionally, you can provide optional names for columns; if not, the columns get default names "A", "B", ..., "Z", "AA", "AB", .... To get a default column name from a column index, use the function `Table.DefaultColumnName`.

The properties `Rows` and `Columns` return two-dimensional immutable arrays containing table values by rows and by columns respectively:

 ```1: ``` ``````let matrixRows = tableMatrix.Rows ``````
 ``seq [seq [11; 12; 13]; seq [21; 22; 23]]``
 ```1: ``` ``````let matrixCols = tableMatrix.Columns ``````
 ``seq [seq [11; 21]; seq [12; 22]; seq [13; 23]]``

To get a value from row and column indices, use the indexed property `Item`:

 ```1: ``` ``````let value = tableMatrix.[0, 0] ``````
 ``11``

Matrix table allows adding rows using `AddRows` and `AddRow` functions:

 ```1: ``` ``````let tableMatrix' = tableMatrix.AddRow [|31;32;33|] ``````
 ``````seq [A[3]: Array is not evaluated yet; B[3]: Array is not evaluated yet; C[3]: Array is not evaluated yet]``````

To add columns, concatenate two matrix tables having same element type and height using function `Table.AppendMatrix`:

 ```1: 2: 3: ``` ``````let tableMatrix'' = Table.OfMatrix ([| [|14|]; [|24|] |], [Table.DefaultColumnName 3]) |> Table.AppendMatrix tableMatrix ``````
 ``````seq [A[2]: int seq [11; 21]; B[2]: int seq [12; 22]; C[2]: int seq [13; 23]; D[2]: int seq [14; 24]]``````