twExtractFromLastDims: twExtractFromLastDims

Description Usage Arguments Author(s) See Also Examples

View source: R/arrayExtract.R

Description

Extract slices i from array Aext keeping the all first dimensions.

Usage

1
twExtractFromLastDims(Aext, i, dPrev = c(1))

Arguments

Aext

array to extract from

i

indices in matrix of last dimensions

dPrev

dimensions in front to keep, defaults to rows

Author(s)

Thomas Wutzler

See Also

twExtractDim, twMisc

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
(A <- matrix(1:6, ncol=2))
(Aext <- abind::abind( lapply(1:4, function(i){(i)/10+A}), along=0 ))
# Note that the second and third dimension of Aext correspond to A 

# Now we whish to extract from Aext based on 
# a criterion for the second and third dimension 
(B <- diag(3)[,1:2])
i <- which(B != 0)
(A[i])
# how to index Aext to obtain those indices?
resExp <- matrix(0,nrow=nrow(Aext),ncol=length(i) )
for( ii in seq(along.with=i) )
    resExp[,ii] <- Aext[,(i[ii]-1) %% 3+1,(i[ii]-1) %/% 3+1]
(res <- twExtractFromLastDims(Aext,i))
identical( resExp, structure(res, dimnames=NULL) )

twMisc documentation built on May 2, 2019, 6:11 p.m.