Learn R Programming

ramify (version 0.1.0)

resize: Resize Matrix

Description

Change shape and size of a matrix.

Usage

resize(x, nrow, ncol, across = c("rows", "columns"), byrow = FALSE)

Arguments

x
A "matrix" or R object.
nrow
The desired number of rows.
ncol
The desired number of columns.
across
Character string specifying whether to flatten the matrix across "rows" (default) or "columns".
byrow
Logical. If FALSE (default) the new matrix is filled by columns, otherwise it is filled by rows.

Value

  • A matrix of dimension nrow-by-ncol.

See Also

flatten, mat, matrix.

Examples

Run this code
m <- 1:9
resize(m)
resize(m, 3, 3)
resize(m, 2, 2)

Run the code above in your browser using DataLab