'Math' and 'Math2' methods for NaArray objects
NaArray-Math-methods.Rd
EXPERIMENTAL!!!
NaArray objects support all operations from the Math
and Math2
groups with a few exceptions.
See ?S4groupGeneric
in the methods package
for more information about the Math
and Math2
group generics.
Note that Math
and Math2
operations only support
NaArray objects of type()
"double"
at the moment.
NaArray objects of type()
"integer"
are not
supported yet.
Value
A NaArray derivative of the same dimensions as the input object.
See also
S4groupGeneric
in the methods package.NaArray objects.
Ordinary array objects in base R.
Examples
nam <- NaArray(dim=c(15, 6))
nam[c(2, 6, 12:17, 22:33, 55, 59:62, 90)] <-
c(runif(22)*1e4, Inf, -Inf, NA, NaN)
log(nam)
#> Warning: NaNs produced
#> <15 x 6 NaMatrix> of type "double" [nnacount=25 (28%)]:
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] NA 8.028196 7.643658 NA NaN NA
#> [2,] 8.584050 9.034220 9.071377 NA NA NA
#> [3,] NA NA 9.200195 NA NA NA
#> [4,] NA NA NA NA NA NA
#> [5,] NA NA NA NA NA NA
#> ... . . . . . .
#> [11,] NA 8.837910 NA NA NA NA
#> [12,] 8.093028 8.431420 NA NA NA NA
#> [13,] 8.965731 9.190522 NA NA NA NA
#> [14,] 8.954927 8.942654 NA 8.682102 NA NA
#> [15,] 8.343868 8.422070 NA Inf NA NaN
exp(nam)
#> <15 x 6 NaMatrix> of type "double" [nnacount=25 (28%)]:
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] NA Inf Inf NA 0 NA
#> [2,] Inf Inf Inf NA NA NA
#> [3,] NA NA Inf NA NA NA
#> [4,] NA NA NA NA NA NA
#> [5,] NA NA NA NA NA NA
#> ... . . . . . .
#> [11,] NA Inf NA NA NA NA
#> [12,] Inf Inf NA NA NA NA
#> [13,] Inf Inf NA NA NA NA
#> [14,] Inf Inf NA Inf NA NA
#> [15,] Inf Inf NA Inf NA NaN
cos(nam)
#> Warning: NaNs produced
#> <15 x 6 NaMatrix> of type "double" [nnacount=25 (28%)]:
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] NA 0.9999406 0.2214054 NA NaN NA
#> [2,] 0.2875817 -0.9665236 0.9244497 NA NA NA
#> [3,] NA NA -0.9949573 NA NA NA
#> [4,] NA NA NA NA NA NA
#> [5,] NA NA NA NA NA NA
#> ... . . . . . .
#> [11,] NA -0.4880495 NA NA NA NA
#> [12,] -0.3788986 -0.6578299 NA NA NA NA
#> [13,] 0.3142635 -0.4101267 NA NA NA NA
#> [14,] 0.3555540 0.1252868 NA -0.9417227 NA NA
#> [15,] 0.6463930 -0.9122549 NA NaN NA NaN
lgamma(nam)
#> <15 x 6 NaMatrix> of type "double" [nnacount=25 (28%)]:
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] NA 21546.80 13864.84 NA Inf NA
#> [2,] 40538.77 67364.70 70238.38 NA NA NA
#> [3,] NA NA 81170.52 NA NA NA
#> [4,] NA NA NA NA NA NA
#> [5,] NA NA NA NA NA NA
#> ... . . . . . .
#> [11,] NA 54004.19 NA NA NA NA
#> [12,] 23202.28 34099.60 NA NA NA NA
#> [13,] 62368.90 80294.25 NA NA NA NA
#> [14,] 61614.99 60769.46 NA 45293.52 NA NA
#> [15,] 30872.71 33739.72 NA Inf NA NaN
## Sanity checks:
m <- as.matrix(nam)
stopifnot(
suppressWarnings(identical(as.matrix(log(nam)), log(m))),
identical(as.matrix(exp(nam)), exp(m)),
suppressWarnings(identical(as.matrix(cos(nam)), cos(m))),
suppressWarnings(identical(as.matrix(lgamma(nam)), lgamma(m)))
)