controlledSubsetting {arrayMagic} | R Documentation

## Subsetting of Arrays

### Description

Finer control on the drop argument as in []

### Usage

    controlledSubsetting(a, ranges, drop)

### Arguments

`a` | array; required; default: missing.
`ranges` | list of vectors; list length must match dimensionality of a; each element of the numeric vector specifies the subset of the corresponding dimension of a; if is.na(element) the whole corresponding dimension is kept; required; default: missing.
`drop` | optional; specifies each dimension of array a which will be dropped, the corresponding subset must specify exact one element; if missing all such subsets are dropped; default: missing.

### Details

### Value

subsetted array

### Author(s)

Andreas Buness <a.buness@dkfz.de>

### See Also

`controlledApply`

### Examples

                a <- array(1:400, dim=c(2,3,5,6))
                r <- controlledSubsetting(a=a, ranges=list(1,2,3,2), drop=2)
                stopifnot(length(dim(r)) == 3 )
                stopifnot(r == a[1,2,3,2])
                r <- controlledSubsetting(a=a, ranges=list(2,1:2,2,2:3), drop=3)
                stopifnot( all(r[1,,,drop=TRUE] == a[2,1:2,2,2:3]) )
                r <- controlledSubsetting(a=a, ranges=list(1:2,1:2,2,3), drop=3)
                stopifnot( all(r[,,1,drop=TRUE] == a[1:2,1:2,2,3]) )
                r <- controlledSubsetting(a=a, ranges=list(1:2,1:2,2,3), drop=c(3,4))
                stopifnot( all(r == a[1:2,1:2,2,3]) )
                r <- controlledSubsetting(a=a, ranges=list(1:2,1:2,1:5,3), drop=c(4))
                stopifnot( all(r == a[1:2,1:2,1:5,3]) )
                r <- controlledSubsetting(a=a, ranges=list(NA,NA,1:5,3), drop=c(4))
                stopifnot( all(r == a[,,1:5,3]) )

[Package arrayMagic version 1.14.0 Index]