subscript-methods.Rd
Methods for "["
, i.e., extraction or subsetting mostly of
matrices, in package Matrix.
There are more than these:
...
...
...
...
...
...
[<–methods
for subassignment to "Matrix"
objects.
Extract
about the standard extraction.
str(m <- Matrix(round(rnorm(7*4),2), nrow = 7))
#> Formal class 'dgeMatrix' [package "Matrix"] with 4 slots
#> ..@ Dim : int [1:2] 7 4
#> ..@ Dimnames:List of 2
#> .. ..$ : NULL
#> .. ..$ : NULL
#> ..@ x : num [1:28] 0.47 0.5 0.89 0.28 1.01 -2.07 1.19 -0.72 0.17 0.92 ...
#> ..@ factors : list()
stopifnot(identical(m, m[]))
m[2, 3] # simple number
#> [1] -0.46
m[2, 3:4] # simple numeric of length 2
#> [1] -0.46 -1.15
m[2, 3:4, drop=FALSE] # sub matrix of class 'dgeMatrix'
#> 1 x 2 Matrix of class "dgeMatrix"
#> [,1] [,2]
#> [1,] -0.46 -1.15
## rows or columns only:
m[1,] # first row, as simple numeric vector
#> [1] 0.47 -0.72 -2.32 -1.48
m[,1:2] # sub matrix of first two columns
#> 7 x 2 Matrix of class "dgeMatrix"
#> [,1] [,2]
#> [1,] 0.47 -0.72
#> [2,] 0.50 0.17
#> [3,] 0.89 0.92
#> [4,] 0.28 -1.67
#> [5,] 1.01 0.45
#> [6,] -2.07 0.48
#> [7,] 1.19 0.76
showMethods("[", inherited = FALSE)
#> Function: [ (package base)
#> x="Matrix", i="ANY", j="NULL", drop="ANY"
#> x="Matrix", i="NULL", j="ANY", drop="ANY"
#> x="Matrix", i="NULL", j="NULL", drop="ANY"
#> x="Matrix", i="index", j="index", drop="logical"
#> x="Matrix", i="index", j="index", drop="missing"
#> x="Matrix", i="index", j="missing", drop="logical"
#> x="Matrix", i="index", j="missing", drop="missing"
#> x="Matrix", i="lMatrix", j="missing", drop="missing"
#> x="Matrix", i="matrix", j="missing", drop="missing"
#> x="Matrix", i="missing", j="index", drop="logical"
#> x="Matrix", i="missing", j="index", drop="missing"
#> x="Matrix", i="missing", j="missing", drop="logical"
#> x="Matrix", i="missing", j="missing", drop="missing"
#> x="Matrix", i="nMatrix", j="missing", drop="missing"
#> x="abIndex", i="index", j="ANY", drop="ANY"
#> x="nonStructure", i="ANY", j="ANY", drop="ANY"
#> x="sparseVector", i="NULL", j="ANY", drop="ANY"
#> x="sparseVector", i="index", j="missing", drop="missing"
#> x="sparseVector", i="lsparseVector", j="missing", drop="missing"
#> x="sparseVector", i="missing", j="missing", drop="missing"
#> x="sparseVector", i="nsparseVector", j="missing", drop="missing"
#>