asub.RdSubset array-like objects at specified indices. asub() is a S3 generic, with
one method, asub.default, supplied in the abind package.
The object to index
A list of indices (e.g., a list of a mixture of integer,
character, and logical vectors, but can actually be anything). Can
be just a vector in the case that length(dims)==1.
NULL entries in the list will be treated as empty indices.
The dimensions on which to index (a numeric or integer vector). The default is all of the dimensions.
The 'drop' argument to index with (the default is to not supply a 'drop' argument
There are no additional arguments allowed for
asub.default but other methods may use them.
Constructs and evaluates an expression to do the requested indexing.
E.g., for x with length(dim(x))==4 the call
asub(x, list(c("a","b"), 3:5), 2:3) will construct and evaluate
the expression x[, c("a","b"), 3:5, ], and the call
asub(x, 1, 2, drop=FALSE) will construct and evaluate
the expression x[, 1, , , drop=FALSE].
asub checks that the elements of dims are in the range 1
to length(dim(x)) (in the case that x is a vector,
length(x) is used for dim(x)). Other than that, no
checks are made on the suitability of components of idx as
indices for x. If the components of idx have any
out-of-range values or unsuitable types, this will be left to the
subsetting method for x to catch.
A subset of x, as returned by x[...].
~put references to the literature/web site here ~
x <- array(1:24,dim=c(2,3,4),dimnames=list(letters[1:2],LETTERS[1:3],letters[23:26]))
asub(x, 1, 1, drop=FALSE)
#> , , w
#>
#> A B C
#> a 1 3 5
#>
#> , , x
#>
#> A B C
#> a 7 9 11
#>
#> , , y
#>
#> A B C
#> a 13 15 17
#>
#> , , z
#>
#> A B C
#> a 19 21 23
#>
asub(x, list(1:2,3:4), c(1,3))
#> , , y
#>
#> A B C
#> a 13 15 17
#> b 14 16 18
#>
#> , , z
#>
#> A B C
#> a 19 21 23
#> b 20 22 24
#>