Learn R Programming

vectools (version 0.3.0)

01_subsetting_operators: Subsetting Operators

Description

Subsetting operators for vector-like objects.

Usage

# S3 method for ObjectArray
[(v, …)
# S3 method for ObjectArray
[[(v, …)
# S3 method for ObjectArray
[[(v, …) <- value

# S3 method for NestMatrix [[(v, i, j, …, drop=TRUE, zero=TRUE) # S3 method for NestMatrix [[(v, i, j) <- value

# S3 method for PartMatrix [[(v, i, j, …, drop=TRUE) # S3 method for PartMatrix [[(v, i, j) <- value

# S3 method for GeomArray [(v, …) # S3 method for ImageArray [(v, …) # S3 method for MatrixArray [(v, …) # S3 method for GeomArray [[(v, …) <- value

#for SectMatrix getSect (v, …, drop=TRUE)

Arguments

v

An ObjectArray (including subclasses) or block matrix object.

i, j, …

The indices.

drop

Logical, if true, reduce the number of dimensions, where possible.

zero

Logical, if true, replace ZERO with zero, or a zero matrix.

value

A suitable value to assign.

Details

ObjectArray (and NestMatrix), are similar to lists, so: Single bracket subsetting returns another ObjectArray, which is a subset of the original. Double bracket subsetting gets or sets a single element within the ObjectArray.

For PartMatrix: Currently, single bracket subsetting is not supported. Currently, double bracket subsetting indexes a single submatrix.

Note that the number of indices used in an ObjectArray depends on the number of dimensions.

The number of indices in PartMatrix objects is always two. And the number of indices for SectMatrix subsetting depends on the VMap object.

Note that there are restrictions on what can be assigned: An ObjectArray may be restricted by its CLASS slot, determined when the object is constructed. Other objects may have restrictions on the sizes of submatrices.

See Also

ObjectArray

NestMatrix

PartMatrix

SectMatrix

Examples

Run this code
# NOT RUN {
x <- matrix (1:16, 4, 4)

pm <- as.PartMatrix (x, 2, 2)
nm <- as.NestMatrix (pm)

#all same
x [1:2, 1:2]
nm [[1, 1]]
pm [[1, 1]]

#all same
x [1, 2]
nm [[1, 1]][1, 2]
pm [[1, 1]][1, 2]
# }

Run the code above in your browser using DataLab