BumpyAtomicMatrix {BumpyMatrix} | R Documentation

## The BumpyAtomicMatrix subclass

### Description

A subclass of the BumpyMatrix where each entry is an atomic vector. One subclass is provided for each of the most common types.

### Details

In the following code snippets, `x` is a BumpyDFrameMatrix.

Binary and unary operations are implemented by specializing Ops, Math and related group generics, and will usually return a new BumpyAtomicMatrix of the appropriate type. The exception is for Summary methods like `max` and `min`; these return an ordinary matrix where each entry contains a scalar value for the corresponding entry of `x`. Furthermore, `range` will return a 3-dimensional array containing the minimum and maximum for each entry of `x`.

Common mathematical operations are implemented that apply to each entry of the BumpyAtomicMatrix:

- `mean`, `sd`, `median`, `mad`, `var` and `IQR` take a single BumpyAtomicMatrix and return an ordinary double-precision matrix of the same dimensions containing the computed statistic for each entry of the input. This is possible as all operations are guaranteed to produce a scalar.

- `quantile` takes a single BumpyAtomicMatrix as input and return a 3-dimensional array. The first dimension contains the requested quantiles, the second dimension corresponds to the rows of `x` and the third dimension corresponds to the columns of `x`.

- `which.max` and `which.min` take a single BumpyAtomicMatrix and return an ordinary integer matrix of the same dimensions containing the index for the min/max value per entry. (This is set to `NA` if the entry of the input has length zero.)

- `pmin`, `pmax`, `pmin.int` and `pmax.int` take multiple BumpyAtomicMatrix objects of the same dimensions, and return a BumpyAtomicMatrix containing the result of running the same function across corresponding entries of the input objects.

- `cor`, `cov` and (optionally) `var` take two BumpyAtomicMatrix objects of the same dimensions, and return an ordinary matrix containing the computed statistic for the corresponding entries of the inputs. This is possible as all operations are guaranteed to produce a scalar.

Additionally, common operations are implemented that apply to each entry of the BumpyCharacterMatrix and return a BumpyAtomicMatrix of the same dimensions and an appropriate type. This includes `tolower`, `toupper`, `substr`, `substring`, `sub`, `gsub`, `grepl`, `grep`, `nchar`, `chartr`, `startsWith` and `endsWith`. We also implement `unstrsplit`, which returns an ordinary matrix of the same dimensions containing the unsplit strings.

All methods implemented for the BumpyMatrix parent class are available here.

### Examples

    # Mocking up a BumpyNumericList:
    library(IRanges)
    x <- splitAsList(runif(1000), factor(sample(50, 1000, replace=TRUE), 1:50))

    # Creating a BumpyNumericMatrix:
    mat <- BumpyMatrix(x, c(10, 5))
    mat[,1]

    # Arithmetic operations:
    (mat * 2)[,1]
    (mat + mat * 5)[,1]

    # Logical operations:
    (mat < 0.5)[,1]
    (mat > 0.5 & mat < 1)[,1]
    (mat == mat)[,1]

    # More statistics:
    max(mat)
    min(mat)
    mean(mat)
    sd(mat)
    median(mat)

    # Handling character vectors:
    x <- splitAsList(sample(LETTERS, 100, replace=TRUE),
        factor(sample(20, 100, replace=TRUE), 1:20))
    cmat <- BumpyMatrix(x, c(5, 4))
    cmat[,1]

    tolower(cmat[,1])
    grepl("A|E|I|O|U", cmat)[,1]
    sub("A|E|I|O|U", "vowel", cmat)[,1]

[Package BumpyMatrix version 1.2.0 Index]