as.array | R Documentation |
Coerces spray objects to arrays. Includes off-by-one functionality via
option offbyone
.
## S3 method for class 'spray'
as.array(x, offbyone=FALSE, compact=FALSE, ...)
## S3 method for class 'spray'
dim(x)
x |
spray object |
offbyone |
Boolean with default |
compact |
Boolean with default |
... |
Further arguments, currently ignored |
Argument offbyone
defaults to FALSE
; but if it is set to
TRUE
, it effectively adds one from the index matrix, so a zero
entry in the index matrix means the first position in that dimension.
After the subtraction, if performed, the function will not operate if any index is less than 1.
Returns an array of dimension dim(S)
. The “meat” of the
function is
out <- array(0, dS) out[ind] <- coeffs(S)
Robin K. S. Hankin
(M <- matrix(sample(0:4,28,replace=TRUE),ncol=4))
(S <- spray(M,sample(7),addrepeats=TRUE))
as.array(S,offbyone=TRUE) # a large object! sprays are terse
S <- spray(matrix(sample(1:4,28,replace=TRUE),ncol=4),sample(7))
A <- as.array(S) # S has no zero indices [if it did, we would need to use offbyone=TRUE]
stopifnot(all(S[index(S),drop=TRUE] == A[index(S)]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.