zmatrix {zmatrix} | R Documentation |
Allows operations with zero-offset matrices.
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, ...)
i, j |
Indices for rows and columns |
m |
A matrix, possibly of class `zmatrix' |
drop |
Lose dimensions of length 1? |
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.
The print method is provided to give zero-index row and column names in the absence of specified names.
Jonathan Rougier, J.C.Rougier@durham.ac.uk, following assistance from Brian Ripley.
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