Learn R Programming

salad (version 1.2)

matrix: Methods for `matrix`, `array`, `as.matrix` and `as.vector`

Description

Methods for `matrix`, `array`, `as.matrix` and `as.vector`

Usage

# S4 method for dual
matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL)

# S4 method for dual array(data = NA, dim = length(data), dimnames = NULL)

# S3 method for dual as.matrix(x, ...)

# S4 method for dual as.matrix(x, ...)

# S3 method for dual as.vector(x, mode = "any")

# S4 method for dual as.vector(x, mode = "any")

Value

A dual object for `matrix` and `array`, a base object for `as.matrix` and `as.vector`.

Arguments

data, x

A dual object

nrow

the desired number of rows

ncol

the desired number of cols

byrow

if `TRUE` the matrix is filled by rows

dimnames

A `dimnames` attributes for a matrix or an array

dim

A `dim` attributes for an array

...

additional arguments (ignored)

mode

The mode of the vector to create

Details

The default behaviour for `as.matrix` dans `as.vector` is to drop the derivatives. This can be modified using `salad` (to use with care). The prefered method to change the shape is to use `dim<-`.

See Also

shape, salad, dual-class

Examples

Run this code
x <- dual(c(1,2,0,4))
y <- matrix(x, 2, 2)
y
as.matrix(y)
dim(x) <- c(2,2)
x

Run the code above in your browser using DataLab