Learn R Programming

rray (version 0.1.0)

as_matrix: Coerce to a matrix

Description

as_matrix() coerces x to a matrix.

Usage

as_matrix(x, ...)

Arguments

x

An object to coerce to a matrix.

...

Objects passed on to methods.

Value

A matrix.

Details

1D arrays are coerced to 1 column matrices.

For a >2D object to be coercible to a matrix, all of the dimensions except for the first two must be size 1. Meaning an array with dimensions (3, 2, 1) would be coercible to a (3, 2) matrix, but one with (3, 1, 2) would not be.

See Also

as_array()

Examples

Run this code
# NOT RUN {
as_matrix(rray(1:10))

# >2D structures can be coerced to matrices
# their first and second dimensions are
# the only ones having a size >1
x <- rray(1, c(2, 2, 1))
as_matrix(x)

# This cannot be coerced to a matrix
y <- rray_reshape(x, c(2, 1, 2))
try(as_matrix(y))

# }

Run the code above in your browser using DataLab