# Stacking vectors and matrices

`matrix-vech.Rd`

Stacks either a lower triangle matrix or a matrix.

## Details

The function `vec`

implements the operator that stacks a matrix
as a column vector, to be more precise in a matrix with one column.
\(vec(X) = (X_{11}, X_{21}, ..., X_{N1}, X_{12}, X_{22}, ..., X_{NN})\).

The function `vech`

implements the operator that stacks the lower
triangle of a NxN matrix as an N(N+1)/2x1 vector:
\(vech(X) =(X_{11}, X_{21}, X_{22}, X_{31}, ..., X_{NN})\),
to be more precise in a matrix with one row.

## Examples

```
## Create Pascal Matrix:
P = pascal(3)
## Stack a matrix
vec(P)
#> [,1]
#> [1,] 1
#> [2,] 1
#> [3,] 1
#> [4,] 1
#> [5,] 2
#> [6,] 3
#> [7,] 1
#> [8,] 3
#> [9,] 6
## Stack the lower triangle
vech(P)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 1 1 2 3 6
```