zmatrix {zmatrix}R Documentation

Zero-offset matrices

Description

Allows operations with zero-offset matrices.

Usage

m[i], m[i, j], m[, j], m[i, j, drop=TRUE]
zmatrix(...)
as.zmatrix(m)
as.matrix.zmatrix(m)
is.zmatrix(m)
print.zmatrix(m, ...)

Arguments

i, j Indices for rows and columns
m A matrix, possibly of class `zmatrix'
drop Lose dimensions of length 1?

Value

With a zero-offset matrix the rows and columns are numbered from zero. zmatrix creates a zero-offset matrix of class `zmatrix', as.zmatrix converts an existing matrix to a zero-offset matrix, and as.matrix converts it back again. Subscripting a zero-offset matrix does not return a zero-offset matrix.

Note

The print method is provided to give zero-index row and column names in the absence of specified names.

Author(s)

Jonathan Rougier, J.C.Rougier@durham.ac.uk, following assistance from Brian Ripley.

See Also

matrix

Examples

fred <- matrix(1:12, 3, 4)
is.zmatrix(fred)                # Not yet!
fred <- as.zmatrix(fred)
fred; print.default(fred)       # note the labels

fred[2, ] <- NA; fred           # sets the third row
fred[, -(0:2)] <- NA; fred      # all bar the first three cols

fred[0, ]                       # a vector
fred[0, , drop=FALSE]           # a matrix
rownames(fred) <- LETTERS[1:3]
fred["A", 0:2]                  # mixture of names and indices