as_matrix: Coerce to a matrix

Description Usage Arguments Details Value See Also Examples

View source: R/coercion.R

Description

as_matrix() coerces x to a matrix.

Usage

1

Arguments

x

An object to coerce to a matrix.

...

Objects passed on to methods.

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.

Value

A matrix.

See Also

as_array()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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))

rray documentation built on July 23, 2019, 5:04 p.m.