Description Usage Arguments Details Value Author(s) See Also Examples
Extract A[...,i,...]
from dimension iDim
of an array
1 | twExtractDim(A, i = 1, iDim = length(dim(A)))
|
A |
the array to extract values from |
i |
the index to extract |
iDim |
the dimension to extract from |
Sometimes the dimension of an array that is to be processed is
only fixed during runtime, i.e. by a value of a variable.
However, with standard [,,]
extraction the syntax is fixed.
Extract A[...,i,...]
from dimension iDim
of an array: this method
Splitting an array by dimesnion and listing subarray: twListArrDim
Extracting from last dimensions: twExtractFromLastDims
Stacking a dimension: twStackArrayDim
If the dimensionality of the array is unknown, then the A[,i,] notation
is not applicable.
This function calculates the indices to extract by using outer
.
vector representing the
Thomas Wutzler
twMisc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | A <- array( 1:(4*2*3), dim=c(4,2,3) )
str(A)
# extract from last dimension
(tmp1 <- twExtractDim(A,3))
identical( tmp1, A[,,3] )
# extract from second dimension
(tmp2 <- twExtractDim(A,2,iDim=2))
identical( tmp2, A[,2,] )
# list all subarrays of last dimension
(tmp3 <- twListArrDim(A))
identical( structure(abind::abind(tmp3,rev.along=0), dimnames=NULL), A )
# list all subarrays of second dimension
(tmp4 <- twListArrDim(A,2))
twExtractFromLastDims(A, 1:2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.