Skip to contents

SparseArray derivatives support a subset of operations from the Math and Math2 groups. See ?S4groupGeneric in the methods package for more information about the Math and Math2 group generics.

IMPORTANT NOTES:

Value

A SparseArray derivative of the same dimensions as the input object.

See also

Examples

m <- matrix(0, nrow=15, ncol=6)
m[c(2, 6, 12:17, 22:33, 55, 59:62, 90)] <-
    c(runif(22)*1e4, Inf, -Inf, NA, NaN)
svt <- SparseArray(m)

svt2 <- trunc(sqrt(svt))
#> Warning: NaNs produced
svt2
#> <15 x 6 SparseMatrix> of type "double" [nzcount=26 (29%)]:
#>       [,1] [,2] [,3] [,4] [,5] [,6]
#>  [1,]    0   82   55    0  NaN    0
#>  [2,]   70   76   83    0   NA    0
#>  [3,]    0    0   97    0    0    0
#>  [4,]    0    0    0    0    0    0
#>  [5,]    0    0    0    0    0    0
#>   ...    .    .    .    .    .    .
#> [11,]    0   12    0    0    0    0
#> [12,]   87   58    0    0    0    0
#> [13,]   92   58    0    0    0    0
#> [14,]   63   97    0   54    0    0
#> [15,]   89    5    0  Inf    0  NaN

## Sanity check:
m2 <- suppressWarnings(trunc(sqrt(m)))
stopifnot(identical(as.matrix(svt2), m2))