Extract.spray
From spray v1.0-8
by Robin K S Hankin
Extract or Replace Parts of a spray
Extract or replace subsets of sprays.
- Keywords
- symbolmath
Usage
# S3 method for spray
[(S, …, drop=FALSE)
# S3 method for spray
[(S, index, …) <- value
Arguments
- S
A spray object
- index
elements to extract or replace
- value
replacement value
- ...
Further arguments
- drop
Boolean, with default
FALSE
meaning to return a spray object andTRUE
meaning to drop the spray structure and return a numeric vector
Details
These methods should work as expected, although the off-by-one issue might be a gotcha.
If drop
is TRUE
, a numeric vector is returned but the
elements may be in any order.
If a <- spray(diag(3))
, for example, then idiom such as
a[c(1,2,3)]
cannot work, because one would like a[1,2,3]
and a[1:3,2,3]
to work.
Examples
# NOT RUN {
a <- spray(diag(5))
a[rbind(rep(1,5))] <- 5
a[3,4,5,3,1] # the NULL polynomial
a[0,1,0,0,0]
a[0,1,0,0,0,drop=TRUE]
a[2,3:5,4,3,3] <- 9
options(polyform = TRUE) # print as a multivariate polynomial
a
options(polyform = FALSE) # print is sparse array form
a
S1 <- spray(diag(5),1:5)
S2 <- spray(1-diag(5),1:5)
S1[] <- 3
S1[] <- S2
# }
Community examples
Looks like there are no examples yet.