Learn R Programming

salad (version 1.2)

shape: Dual objects length, dim, names and dimnames

Description

S3 methods for length, dim, names and dimnames

Usage

# S3 method for dual
length(x)

# S3 method for dual dim(x)

# S3 method for dual dim(x) <- value

# S3 method for dual dimnames(x)

# S3 method for dual dimnames(x) <- value

# S3 method for dual names(x)

# S3 method for dual names(x) <- value

Value

Return values are similar to the base methods.

Arguments

x

a dual object

value

for replacement methods, the new value

Details

As the methods `dimnames` and `dimnanes<-.dual` have been defined, you can use `rownames` and `colnames` as with numeric matrices (see examples).

Examples

Run this code
x <- dual( matrix(c(1,0,2,3,2,4), 2, 3) )
dim(x)
length(x)
rownames(x) <- c("L1", "L2")
x
d(x, "x1.1")

# modifying dim is the recommended way to change dual object shape
dim(x) <- NULL
x

# back to matrix shape
dim(x) <- c(2, 3)
x

Run the code above in your browser using DataLab