Reshape matrix or vector.

Reshape(a, n, m)

Arguments

a

matrix or vector

n, m

size of the result

Details

Reshape(a, n, m) returns the n-by-m matrix whose elements are taken column-wise from a.

An error results if a does not have n*m elements. If m is missing, it will be calculated from n and the size of a.

Value

Returns matrix (or array) of the requested size containing the elements of a.

Examples

a <- matrix(1:12, nrow=4, ncol=3)
Reshape(a, 6, 2)
#>      [,1] [,2]
#> [1,]    1    7
#> [2,]    2    8
#> [3,]    3    9
#> [4,]    4   10
#> [5,]    5   11
#> [6,]    6   12
Reshape(a, 6)     # the same
#>      [,1] [,2]
#> [1,]    1    7
#> [2,]    2    8
#> [3,]    3    9
#> [4,]    4   10
#> [5,]    5   11
#> [6,]    6   12
Reshape(a, 3, 4)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    4    7   10
#> [2,]    2    5    8   11
#> [3,]    3    6    9   12