[<–methods {Matrix} | R Documentation |
Methods for "[<-"
, i.e., extraction or subsetting mostly of
matrices, in package Matrix.
Note: Contrary to standadrd matrix
assignment in
base R, in x[..] <- val
it is typically an error (see
stop
) when the type or class
of
val
would require the class of x
to be changed, e.g.,
when x
is logical, say "lsparseMatrix"
, and val
is numeric.
There are many many more than these:
is currently a simple fallback method implementation which ensures “readable” error messages.
currently gives an error
...
...
...
[-methods
for subsetting "Matrix"
objects; the
index
class;
Extract
about the standard subset assignment (and extraction).
set.seed(101) (a <- m <- Matrix(round(rnorm(7*4),2), nrow = 7)) a[] <- 2.2 # <<- replaces **every** entry a ## as do these: a[,] <- 3 ; a[TRUE,] <- 4 m[2, 3] <- 3.14 # simple number m[3, 3:4]<- 3:4 # simple numeric of length 2 ## sub matrix assignment: m[-(4:7), 3:4] <- cbind(1,2:4) #-> upper right corner of 'm' m[3:5, 2:3] <- 0 m[6:7, 1:2] <- Diagonal(2) m ## rows or columns only: m[1,] <- 10 m[,2] <- 1:7 m[-(1:6), ] <- 3:0 # not the first 6 rows, i.e. only the 7th as(m, "sparseMatrix")