Description Usage Arguments Author(s) See Also Examples
Extract slices i from array Aext keeping the all first dimensions.
1 | twExtractFromLastDims(Aext, i, dPrev = c(1))
|
Aext |
array to extract from |
i |
indices in matrix of last dimensions |
dPrev |
dimensions in front to keep, defaults to rows |
Thomas Wutzler
twExtractDim, twMisc
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) )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.