Skip to contents

This man page documents various base array operations that are supported by SparseArray derivatives, and that didn't belong to any of the groups of operations documented in the other man pages of the SparseArray package.

Usage

# --- unary isometric array transformations ---

# S4 method for class 'COO_SparseArray'
is.na(x)
# S4 method for class 'SVT_SparseArray'
is.na(x)

# S4 method for class 'COO_SparseArray'
is.nan(x)
# S4 method for class 'SVT_SparseArray'
is.nan(x)

# S4 method for class 'COO_SparseArray'
is.infinite(x)
# S4 method for class 'SVT_SparseArray'
is.infinite(x)

# S4 method for class 'COO_SparseArray'
tolower(x)

# S4 method for class 'COO_SparseArray'
toupper(x)

# S4 method for class 'COO_SparseArray'
nchar(x, type="chars", allowNA=FALSE, keepNA=NA)

# --- N-ary isometric array transformations ---

# S4 method for class 'SparseArray'
pmin(..., na.rm=FALSE)
# S4 method for class 'SparseArray'
pmax(..., na.rm=FALSE)

Arguments

x

A SparseArray derivative.

type, allowNA, keepNA

See ?base::nchar for a description of these arguments.

...

SparseArray derivatives.

na.rm

See ?base::pmin for a description of this argument.

Details

More operations will be added in the future.

Value

See man pages of the corresponding base functions (e.g. ?base::is.na, ?base::nchar, ?base::pmin, etc...) for the value returned by these methods.

Note that, like the base functions, the methods documented in this man page are endomorphisms i.e. they return an array-like object of the same class as the input.

See also

Examples

a <- array(c(0, 2.77, NA, 0, NaN, -Inf), dim=5:3)
svt <- SparseArray(a)  # SVT_SparseArray object
class(svt)
#> [1] "SVT_SparseArray"
#> attr(,"package")
#> [1] "SparseArray"

is.na(svt)             # SVT_SparseArray object of type "logical"
#> <5 x 4 x 3 SparseArray> of type "logical" [nzcount=20 (33%)]:
#> ,,1
#>       [,1]  [,2]  [,3]  [,4]
#> [1,] FALSE FALSE  TRUE FALSE
#> [2,] FALSE FALSE FALSE  TRUE
#> [3,]  TRUE FALSE FALSE FALSE
#> [4,] FALSE  TRUE FALSE FALSE
#> [5,]  TRUE FALSE  TRUE FALSE
#> 
#> ,,2
#>       [,1]  [,2]  [,3]  [,4]
#> [1,]  TRUE FALSE FALSE FALSE
#> [2,] FALSE  TRUE FALSE FALSE
#> [3,]  TRUE FALSE  TRUE FALSE
#> [4,] FALSE  TRUE FALSE  TRUE
#> [5,] FALSE FALSE  TRUE FALSE
#> 
#> ,,3
#>       [,1]  [,2]  [,3]  [,4]
#> [1,]  TRUE FALSE  TRUE FALSE
#> [2,] FALSE  TRUE FALSE  TRUE
#> [3,] FALSE FALSE  TRUE FALSE
#> [4,] FALSE FALSE FALSE  TRUE
#> [5,]  TRUE FALSE FALSE FALSE
#> 
is.nan(svt)            # SVT_SparseArray object of type "logical"
#> <5 x 4 x 3 SparseArray> of type "logical" [nzcount=10 (17%)]:
#> ,,1
#>       [,1]  [,2]  [,3]  [,4]
#> [1,] FALSE FALSE  TRUE FALSE
#> [2,] FALSE FALSE FALSE  TRUE
#> [3,] FALSE FALSE FALSE FALSE
#> [4,] FALSE FALSE FALSE FALSE
#> [5,]  TRUE FALSE FALSE FALSE
#> 
#> ,,2
#>       [,1]  [,2]  [,3]  [,4]
#> [1,] FALSE FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE FALSE
#> [3,]  TRUE FALSE FALSE FALSE
#> [4,] FALSE  TRUE FALSE FALSE
#> [5,] FALSE FALSE  TRUE FALSE
#> 
#> ,,3
#>       [,1]  [,2]  [,3]  [,4]
#> [1,]  TRUE FALSE FALSE FALSE
#> [2,] FALSE  TRUE FALSE FALSE
#> [3,] FALSE FALSE  TRUE FALSE
#> [4,] FALSE FALSE FALSE  TRUE
#> [5,] FALSE FALSE FALSE FALSE
#> 
is.infinite(svt)       # SVT_SparseArray object of type "logical"
#> <5 x 4 x 3 SparseArray> of type "logical" [nzcount=10 (17%)]:
#> ,,1
#>       [,1]  [,2]  [,3]  [,4]
#> [1,] FALSE  TRUE FALSE FALSE
#> [2,] FALSE FALSE  TRUE FALSE
#> [3,] FALSE FALSE FALSE  TRUE
#> [4,] FALSE FALSE FALSE FALSE
#> [5,] FALSE FALSE FALSE FALSE
#> 
#> ,,2
#>       [,1]  [,2]  [,3]  [,4]
#> [1,] FALSE FALSE FALSE  TRUE
#> [2,] FALSE FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE FALSE
#> [4,]  TRUE FALSE FALSE FALSE
#> [5,] FALSE  TRUE FALSE FALSE
#> 
#> ,,3
#>       [,1]  [,2]  [,3]  [,4]
#> [1,] FALSE FALSE FALSE FALSE
#> [2,]  TRUE FALSE FALSE FALSE
#> [3,] FALSE  TRUE FALSE FALSE
#> [4,] FALSE FALSE  TRUE FALSE
#> [5,] FALSE FALSE FALSE  TRUE
#> 

svt1 <- poissonSparseMatrix(500, 20, density=0.2)
svt2 <- poissonSparseMatrix(500, 20, density=0.25) * 0.77
pmin(svt1, svt2)
#> <500 x 20 SparseMatrix> of type "double" [nzcount=534 (5.3%)]:
#>         [,1]  [,2]  [,3] ... [,19] [,20]
#>   [1,]     0     0     0   .     0     0
#>   [2,]     0     0     0   .     0     0
#>   [3,]     0     0     1   .     0     0
#>   [4,]     0     0     0   .     0     0
#>   [5,]     0     0     0   .     0     0
#>    ...     .     .     .   .     .     .
#> [496,]  0.00  0.00  0.00   .     0     0
#> [497,]  0.00  0.00  0.77   .     0     0
#> [498,]  0.00  0.00  0.00   .     0     0
#> [499,]  0.00  0.00  0.00   .     0     0
#> [500,]  0.77  0.00  0.00   .     0     0
pmax(svt1, svt2)
#> <500 x 20 SparseMatrix> of type "double" [nzcount=4005 (40%)]:
#>         [,1]  [,2]  [,3] ... [,19] [,20]
#>   [1,]  0.00  0.00  0.00   .  0.77  0.77
#>   [2,]  0.00  0.00  0.00   .  0.00  2.00
#>   [3,]  0.00  0.00  1.54   .  1.00  1.54
#>   [4,]  0.00  0.00  0.00   .  0.00  0.00
#>   [5,]  0.00  1.00  0.77   .  0.00  0.77
#>    ...     .     .     .   .     .     .
#> [496,]  0.00  0.00  0.77   .  1.00  0.77
#> [497,]  0.00  0.00  1.00   .  0.00  0.00
#> [498,]  1.00  1.00  0.00   .  2.31  0.00
#> [499,]  0.00  0.77  0.00   .  1.54  1.00
#> [500,]  1.00  0.00  0.00   .  1.00  0.00

## Sanity checks:
res <- is.na(svt)
stopifnot(is(res, "SVT_SparseArray"), type(res) == "logical",
          identical(as.array(res), is.na(a)))
res <- is.nan(svt)
stopifnot(is(res, "SVT_SparseArray"), type(res) == "logical",
          identical(as.array(res), is.nan(a)))
res <- is.infinite(svt)
stopifnot(is(res, "SVT_SparseArray"), type(res) == "logical",
          identical(as.array(res), is.infinite(a)))
res <- pmin(svt1, svt2)
stopifnot(is(res, "SVT_SparseArray"),
          identical(as.array(res), pmin(as.array(svt1), as.array(svt2))))
res <- pmax(svt1, svt2)
stopifnot(is(res, "SVT_SparseArray"),
          identical(as.array(res), pmax(as.array(svt1), as.array(svt2))))