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 |
give.indices |
Boolean, with default |
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