Xtrct-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.06 -0.16 -1.47 -0.48 0.42 1.36 -0.1 0.39 -0.05 -1.38 ...
#> ..@ factors : list()
stopifnot(identical(m, m[]))
m[2, 3] # simple number
#> [1] -0.16
m[2, 3:4] # simple numeric of length 2
#> [1] -0.16 0.77
m[2, 3:4, drop=FALSE] # sub matrix of class 'dgeMatrix'
#> 1 x 2 Matrix of class "dgeMatrix"
#> [,1] [,2]
#> [1,] -0.16 0.77
## rows or columns only:
m[1,] # first row, as simple numeric vector
#> [1] -0.06 0.39 0.76 0.36
m[,1:2] # sub matrix of first two columns
#> 7 x 2 Matrix of class "dgeMatrix"
#> [,1] [,2]
#> [1,] -0.06 0.39
#> [2,] -0.16 -0.05
#> [3,] -1.47 -1.38
#> [4,] -0.48 -0.41
#> [5,] 0.42 -0.39
#> [6,] 1.36 -0.06
#> [7,] -0.10 1.10
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"
#>