subsetting {matrixset} | R Documentation |
Subsetting matrixsets
Description
Extract parts of a matrixset, where indexes refers to rows and columns.
Usage
## S3 method for class 'matrixset'
x[
i = NULL,
j = NULL,
matrix = NULL,
drop = FALSE,
keep_annotation = TRUE,
warn_class_change = getOption("matrixset.warn_class_change")
]
## S3 method for class 'row_grouped_ms'
x[
i = NULL,
j = NULL,
matrix = NULL,
drop = FALSE,
keep_annotation = TRUE,
warn_class_change = getOption("matrixset.warn_class_change")
]
## S3 method for class 'col_grouped_ms'
x[
i = NULL,
j = NULL,
matrix = NULL,
drop = FALSE,
keep_annotation = TRUE,
warn_class_change = getOption("matrixset.warn_class_change")
]
## S3 method for class 'dual_grouped_ms'
x[
i = NULL,
j = NULL,
matrix = NULL,
drop = FALSE,
keep_annotation = TRUE,
warn_class_change = getOption("matrixset.warn_class_change")
]
## S3 method for class 'matrixset'
x$matrix
## S3 method for class 'matrixset'
x[[matrix]]
Arguments
x |
|
i , j |
rows ( To extract every rows or columns, use Numeric values are coerced to integer through Character vectors will be matched to the dimnames of the object. Indices an also be logical vectors, stating for each element if it is
extracted ( Can also be negative integers, in which case they are indices of elements to leave out of the selection. When indexing, a single argument |
matrix |
index specifying matrix or matrices to extract.
Index is numeric or character vectors or empty
( See arguments |
drop |
If |
keep_annotation |
|
warn_class_change |
|
Details
Indexes i
and j
are given as for a regular matrix()
(note however that factors are currently not allowed for indexing).
Which matrices are extracted (all or a subset) is specified via argument
"matrix"
.
Missing values (NA
) are not allowed for indexing, as it results in
unknown selection. Character indexes use exact matching, not partial.
The default arguments for "drop"
and "keep_annotation"
are
chosen so that the object resulting from the extraction is still a
matrixset
.
Setting "keep_annotation"
to FALSE
automatically results in a class
change (a list of matrix) and a warning is issued (see argument
warn_class_change
, however).
Setting drop
to TRUE
may also result to a change of class,
depending on the provided indices (the same way matrix may result to a vector
when drop
is TRUE
).
The subsetting operator [[
is a convenient wrapper for [(,,matrix)
.
There is no $
subsetting operator for the matrixset
object.
Value
The resulting object type depends on the subsetting options. By default, a
matrixset
object will be returned. This object will have the following
properties:
Rows and/or columns are a subset of the input (based on what has been subsetted), but appear in the same order.
Annotations, or traits, are subsetted appropriately.
The number of groups may be reduced.
Currently, attributes are not preserved.
If keep_annotation
is FALSE
, the resulting object will be a list.
Typically, it will be a list of matrix
, but if drop
is TRUE
, some
list elements could be vectors.
Grouped matrixset
When subsetting a grouped matrixset
(by rows and/or columns), when the
resulting object is still a matrixset
, the grouping structure will be
updated based on the resulting data.
Examples
lst <- list(a = matrix(1:6, 2, 3), b = matrix(101:106, 2, 3), c = NULL)
rownames(lst$a) <- rownames(lst$b) <- c("r1", "r2")
colnames(lst$a) <- colnames(lst$b) <- c("c1", "c2", "c3")
ri <- data.frame(rowname = c("r1", "r2"), g = 1:2)
ci <- data.frame(colname = c("c1", "c2", "c3"), h = 1:3)
matset <- matrixset(lst, row_info = ri, column_info = ci, row_tag = "foo", column_tag = "bar")
# this doesn't subset anything, just returns matset again
matset[]
# this extracts the first row of every matrix. Note how each matrices is
# still a matrix, so you still end up with a matrixset object. Note also
# that you need placeholder for j and matrix index, even when not provided
matset[1, , ]
# similar idea
matset[,2, ]
matset[1,2,]
# it obviously works with vector indexes
matset[1:2, c(1,3),]
# you can extract the matrices this - even without the 'annoying' warning
matset[, , , keep_annotation = FALSE]
matset[, , , keep_annotation = FALSE, warn_class_change = FALSE]
# extracts subsetted matrices (no annotations)
matset[1, , , keep_annotation = FALSE, warn_class_change = FALSE]
# a bit more in line with how R subsets matrices
matset[1, , , drop = TRUE, warn_class_change = FALSE]
# you can obviously get some of the matrices only
matset[,,1]
matset[c(1,2),,1:2]
# to showcase other kind of indexes. These are all equivalents
matset[1,,]
matset["r1", ,]
matset[c(TRUE, FALSE), ,]
matset[-2, ,] # equivalent because there are only 2 rows
# this is also equivalent
matset[,,1]
matset[[1]]