adrop.RdDrop degenerate dimensions of an array object. Offers less
automaticity and more control than the base drop() function.
adrop() is a S3 generic, with one method, adrop.default,
supplied in the abind package.
adrop(x, drop = TRUE, named.vector = TRUE, one.d.array = FALSE, ...)An array (including a matrix)
A logical or numeric vector describing exactly which dimensions to
drop. It is intended that this argument be supplied always. The
default is very rarely useful (drop=TRUE means drop the first
dimension of a 1-d array).
Optional, defaults to TRUE. Controls
whether a vector result has names derived from the dimnames
of x.
Optional, defaults to FALSE. If
TRUE, a one-dimensional array result will be an object with a
dim attribute of
length 1, and possibly a dimnames attribute. If
FALSE, a one-dimensional result will be a vector object
(named if named.vector==TRUE).
There are no additional arguments allowed for
adrop.default but other methods may use them.
Dimensions can only be dropped if their extent is one, i.e., dimension
i of array x can be dropped only if dim(x)[i]==1.
It is an error to request adrop to drop a dimension whose
extent is not 1.
A 1-d array can be converted to a named vector by supplying
drop=NULL (which means drop no dimensions, and return a 1-d
array result as a named vector).
If x is an object with a dim attribute (e.g., a matrix or
array), then adrop returns an object like x,
but with the requested
extents of length one removed. Any accompanying dimnames
attribute is adjusted and returned with x.
x <- array(1:24,dim=c(2,3,4),dimnames=list(letters[1:2],LETTERS[1:3],letters[23:26]))
adrop(x[1,,,drop=FALSE],drop=1)
#> w x y z
#> A 1 7 13 19
#> B 3 9 15 21
#> C 5 11 17 23
adrop(x[,1,,drop=FALSE],drop=2)
#> w x y z
#> a 1 7 13 19
#> b 2 8 14 20
adrop(x[,,1,drop=FALSE],drop=3)
#> A B C
#> a 1 3 5
#> b 2 4 6
adrop(x[1,1,1,drop=FALSE],drop=1)
#> w
#> A 1
adrop(x[1,1,1,drop=FALSE],drop=2)
#> w
#> a 1
adrop(x[1,1,1,drop=FALSE],drop=3)
#> A
#> a 1
adrop(x[1,1,1,drop=FALSE],drop=1:2)
#> w
#> 1
adrop(x[1,1,1,drop=FALSE],drop=1:2,one.d=TRUE)
#> w
#> 1
adrop(x[1,1,1,drop=FALSE],drop=1:2,named=FALSE)
#> [1] 1
dim(adrop(x[1,1,1,drop=FALSE],drop=1:2,one.d=TRUE))
#> [1] 1
dimnames(adrop(x[1,1,1,drop=FALSE],drop=1:2,one.d=TRUE))
#> [[1]]
#> [1] "w"
#>
names(adrop(x[1,1,1,drop=FALSE],drop=1:2,one.d=TRUE))
#> [1] "w"
dim(adrop(x[1,1,1,drop=FALSE],drop=1:2))
#> NULL
dimnames(adrop(x[1,1,1,drop=FALSE],drop=1:2))
#> NULL
names(adrop(x[1,1,1,drop=FALSE],drop=1:2))
#> [1] "w"