type | R Documentation |
The S4Arrays package defines a couple of type()
methods to get
the type of the elements of a matrix-like or array-like object.
## S4 method for signature 'ANY'
type(x)
## S4 method for signature 'DataFrame'
type(x)
x |
For the default For the method for DataFrame objects:
A DataFrame derivative for which
|
Note that for an ordinary matrix or array x
, type(x)
is
the same as typeof(x)
.
On an array-like object x
that is not an ordinary array,
type(x)
is semantically equivalent to
typeof(as.array(x))
. However, the actual implementation is
careful to avoid turning the full array-like object x
into
an ordinary array, as this would tend to be very inefficient in general.
For example, doing so on a big DelayedArray object
could easily eat all the memory available on the machine.
On a DataFrame object, type(x)
only
works if as.data.frame(x)
preserves the number of columns,
in which case it is semantically equivalent to
typeof(as.matrix(as.data.frame(x)))
. Here too, the actual
implementation is careful to avoid turning the full object into a
data frame, then into a matrix, for efficiency reasons.
A single string indicating the type of the array elements in x
.
The type
generic function defined
in the BiocGenerics package.
SparseArray objects implemented in the SparseArray package.
DelayedArray objects implemented in the DelayedArray package.
DataFrame objects implemented in the S4Vectors package.
m <- matrix(rpois(54e6, lambda=0.4), ncol=1200)
type(m) # integer
x1 <- as(m, "dgCMatrix")
type(x1) # double
library(SparseArray)
x2 <- SparseArray(m)
type(x2) # integer
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.