R: Replacements for APL functions take and drop

apl {magic} | R Documentation

## Replacements for APL functions take and drop

### Description

Replacements for APL functions take and drop

### Usage

    apldrop(a, b, give.indices=FALSE)
    apldrop(a, b) <- value
    apltake(a, b, give.indices=FALSE)
    apltake(a, b) <- value

### Arguments

`a` | Array
`b` | Vector of number of indices to take/drop. Length of `b` should not exceed `length(dim(a))`; if it does, an error is returned
`give.indices` | Boolean, with default `FALSE` meaning to return the appropriate subset of array `a`, and `TRUE` meaning to return the list of the selected elements in each of the dimensions. Setting to `TRUE` is not really intended for the end-user, but is used in the code of `apltake<-()` and `apldrop<-()`
`value` | elements to replace

### Details

`apltake(a,b)` returns an array of the same dimensionality as `a`. Along dimension `i`, if `b[i]>0`, the first `b[i]` elements are retained; if `b[i]<0`, the last `b[i]` elements are retained.

`apldrop(a,b)` returns an array of the same dimensionality as `a`. Along dimension `i`, if `b[i]>0`, the first `b[i]` elements are dropped if `b[i]<0`, the last `b[i]` elements are dropped.

These functions do not drop singleton dimensions. Use `drop()` if this is desired.

### Author(s)

Robin K. S. Hankin

### Examples

    a <- magichypercube.4n(m=1)
    apltake(a,c(2,3,2))
    apldrop(a,c(1,1,2))

    b <- matrix(1:30,5,6)
    apldrop(b,c(1,-2)) <- -1

    b <- matrix(1:110,10,11)
    apltake(b,2) <- -1
    apldrop(b,c(5,-7)) <- -2
    b

[Package magic version 1.5-6 Index]