dplyr-methods {Cardinal} | R Documentation

## Data transformation and summarization

### Description

These methods provide analogs of data manipulation verbs from the `dplyr` package, with appropriate semantics for imaging experiments. Due to the differences between imaging datasets and standard data frames, they do not always work identically.

See the descriptions below for details.

### Usage

    ## S4 method for signature 'ImagingExperiment'
    filter(.data, ..., .preserve=FALSE)

    ## S4 method for signature 'ImagingExperiment'
    select(.data, ...)

    ## S4 method for signature 'ImagingExperiment'
    mutate(.data, ...)

    ## S4 method for signature 'SparseImagingExperiment'
    summarize(.data, ...,
        .by = c("feature", "pixel"), .group_by,
        .stat = c("min", "max", "mean", "sum", "sd", "var"),
        .tform = identity,
        BPPARAM = bpparam())

### Arguments

`.data` | An imaging dataset.
`...` | Conditions describing rows or columns to be retained, name-value pairs to be added as metadata columns, or name-value pairs of summary functions. See Details.
`.preserve` | Ignored, provided for compatibility with dplyr.
`.by` | Should the summarization be performed over pixels or features?
`.group_by` | A grouping variable for summarization. The summary functions will be applied within each group.
`.stat` | Summary statistics to be computed in an efficient manner.
`.tform` | How should each feature-vector or image-vector be transformed before summarization?
`BPPARAM` | An optional `BiocParallelParam` instance to be passed to `bplapply()`.

### Details

`filter()` keeps only the rows (features) where the conditions are TRUE. Columns of `featureData(.data)` can be referred to literally in the logical expressions.

`select()` keeps only the columns (pixels) where the conditions are TRUE. Columns of `pixelData(.data)` can be referred to literally in the logical expressions.

`mutate()` adds new columns to the pixel metadata columns (`pixelData(.data)`).

`summarize()` calculates statistical summaries over either features or pixels using `pixelApply()` or `featureApply()`. Several statistical summaries can be chosen via the `.stat` argument, which will be efficiently calculated according to the format of the data.

### Value

An `ImagingExperiment` (or subclass) instance for `filter()`, `select()`, and `mutate()`. An `XDataFrame` (or subclass) instance for `summarize()`.

### Author(s)

Kylie A. Bemis

### Examples

    register(SerialParam())

    set.seed(1)
    mse <- simulateImage(preset=1, npeaks=10, dim=c(10,10))

    # filter features to mass range 1000 - 1500
    filter(mse, 1000 < mz, mz < 1500)

    # select pixels to coordinates x = 1..3, y = 1..3
    select(mse, x <= 3, y <= 3)

    # summarize mean spectrum
    sm1 <- summarize(mse, .stat="mean")

    # summarize image by TIC
    sm2 <- summarize(mse, .stat=c(tic="sum"), .by="pixel")

    # add a TIC column
    mutate(mse, tic=sm2$tic)

    # summarize mean spectrum grouped by pixels in/out of circle
    sm3 <- summarize(mse, .stat="mean", .group_by=mse$circle)

[Package Cardinal version 2.2.6 Index]