twExtractDim: twExtractDim

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/arrayExtract.R

Description

Extract A[...,i,...] from dimension iDim of an array

Usage

1
twExtractDim(A, i = 1, iDim = length(dim(A)))

Arguments

A

the array to extract values from

i

the index to extract

iDim

the dimension to extract from

Details

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.

Array functionality of package twMisc
  • 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.

Value

vector representing the

Author(s)

Thomas Wutzler

See Also

twMisc

Examples

 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)

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