1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
\name{NaArray}
\docType{class}
\alias{class:NaArray}
\alias{NaArray-class}
\alias{NaArray}
\alias{class:NaMatrix}
\alias{NaMatrix-class}
\alias{NaMatrix}
\alias{coerce,NaArray,NaMatrix-method}
\alias{coerce,NaMatrix,NaArray-method}
\alias{dim,NaArray-method}
\alias{dimnames,NaArray-method}
\alias{dimnames<-,NaArray,ANY-method}
\alias{type,NaArray-method}
\alias{type<-,NaArray-method}
\alias{is_nonna,NaArray-method}
\alias{nnacount,NaArray-method}
\alias{nnawhich,NaArray-method}
\alias{as.array.NaArray}
\alias{as.array,NaArray-method}
\alias{coerce,array,NaArray-method}
\alias{coerce,matrix,NaMatrix-method}
\alias{show,NaArray-method}
\title{NaArray objects}
\description{
EXPERIMENTAL!!!
Like \link{SVT_SparseArray} objects but the background value is \code{NA}
instead of zero.
}
\usage{
## Constructor function:
NaArray(x, dim=NULL, dimnames=NULL, type=NA)
}
\arguments{
\item{x}{
If \code{dim} is \code{NULL} (the default) then \code{x} must be an
ordinary matrix or array, or a dgCMatrix/lgCMatrix object, or any
matrix-like or array-like object that supports coercion to NaArray.
If \code{dim} is provided then \code{x} can either be missing, a
vector (atomic or list), or an array-like object. If missing, then
an all-NA NaArray object will be constructed. Otherwise \code{x}
will be used to fill the returned object (\code{length(x)} must be
\code{<= prod(dim)}). Note that if \code{x} is an array-like object
then its dimensions are ignored i.e. it's treated as a vector.
}
\item{dim}{
\code{NULL} or the dimensions (supplied as an integer vector) of
the NaArray or NaMatrix object to construct.
If \code{NULL} (the default) then the returned object will have
the dimensions of matrix-like or array-like object \code{x}.
}
\item{dimnames}{
The \emph{dimnames} of the object to construct. Must be \code{NULL} or
a list of length the number of dimensions. Each list element must be
either \code{NULL} or a character vector along the corresponding dimension.
If both \code{dim} and \code{dimnames} are \code{NULL} (the default) then
the returned object will have the \emph{dimnames} of matrix-like or
array-like object \code{x}.
}
\item{type}{
A single string specifying the requested type of the object.
By default the NaArray object returned by the constructor
function will have the same \code{type()} as \code{x}. However the
user can use the \code{type} argument to request a different type.
Note that doing:
\preformatted{ naa <- NaArray(x, type=type)}
is equivalent to doing:
\preformatted{ naa <- NaArray(x)
type(naa) <- type}
but the former is more convenient and will generally be more efficient.
The supported types for NaArray objects are \code{"integer"},
\code{"logical"}, \code{"double"}, \code{"complex"}, and
\code{"character"}.
}
}
\details{
NaArray is a concrete subclass of the \link{Array} virtual class.
This makes NaArray objects Array derivatives.
Like with \link{SVT_SparseArray} objects, the non-NA data in an NaArray
object is stored in a \emph{Sparse Vector Tree}.
See \code{?\link{SVT_SparseArray}} for more information.
}
\value{
An NaArray or NaMatrix object.
}
\seealso{
\itemize{
\item The \link{SVT_SparseArray} class.
\item \link{is_nonna} for \code{is_nonna()} and \code{nna*()} functions
\code{nnacount()}, \code{nnawhich()}, etc...
\item \link{NaArray_aperm} for permuting the dimensions of an
NaArray object (e.g. transposition).
\item \link{NaArray_subsetting} for subsetting an NaArray object.
\item \link{NaArray_abind} for combining 2D or multidimensional
NaArray objects.
\item \link{NaArray_summarization} for NaArray summarization
methods.
\item \link{NaArray_Arith}, \link{NaArray_Compare}, and
\link{NaArray_Logic}, for operations from the \code{Arith},
\code{Compare}, and \code{Arith} groups on NaArray objects.
\item \link{NaArray_Math} for operations from the \code{Math} and
\code{Math2} groups on NaArray objects.
\item \link{NaArray_misc} for miscellaneous operations on an
NaArray object.
\item \link{NaArray_matrixStats} for col/row summarization methods
for NaArray objects.
\item Ordinary \link[base]{array} objects in base R.
}
}
\examples{
## ---------------------------------------------------------------------
## Display details of class definition & known subclasses
## ---------------------------------------------------------------------
showClass("NaArray")
## ---------------------------------------------------------------------
## The NaArray() constructor
## ---------------------------------------------------------------------
naa1 <- NaArray(dim=5:3) # all-NA object
naa1
naa2 <- NaArray(dim=c(35000, 2e6), type="integer") # all-NA object
naa2
## Add some non-NA values to 'naa2':
naa2[cbind( 1:99, 2:100)] <- 1L
naa2[cbind(1:100, 1:100)] <- 0L
naa2[cbind(2:100, 1:99)] <- -1L
naa2
## The dimnames can be specified at construction time, or
## added/modified later:
naa3 <- NaArray(c(NA, NA, 1L, NA, 0:7, rep(NA, 4), 12:14, NA),
dim=4:5, dimnames=list(letters[1:4], LETTERS[1:5]))
naa3
colnames(naa3) <- LETTERS[22:26]
naa3
## Sanity checks:
stopifnot(
is(naa1, "NaArray"),
identical(dim(naa1), 5:3),
identical(as.array(naa1), array(dim=5:3)),
is(naa2, "NaMatrix"),
all.equal(dim(naa2), c(35000, 2e6)),
identical(nnacount(naa2), 298L),
is(naa3, "NaMatrix"),
identical(dim(naa3), 4:5),
identical(nnacount(naa3), 12L)
)
}
\keyword{methods}
\keyword{classes}
|