Learn R Programming

pracma (version 0.7.5)

reshape: Reshape Matrix

Description

Reshape matrix or vector.

Usage

reshape(a, n, m)

Arguments

a
matrix or vector
n, m
size of the result

Value

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

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.

Examples

Run this code
a <- matrix(1:12, nrow=4, ncol=3)
reshape(a, 6, 2)
reshape(a, 6)     # the same
reshape(a, 3, 4)

Run the code above in your browser using DataLab