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

    ## S3 method for class 'SparseImagingExperiment'
    filter(.data, ..., .preserve=FALSE)

    ## S3 method for class 'SparseImagingExperiment'
    select(.data, ...)

    ## S3 method for class 'SparseImagingExperiment'
    mutate(.data, ...)

    ## S3 method for class 'SparseImagingExperiment'
    summarise(.data, ...,
        .by = c("feature", "pixel"), .groups = NULL,
        .stat = "mean", .tform = identity,
        .as = "ImagingExperiment",
        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?
`.groups` | A grouping variable for summarization. The summary functions will be applied within each group.
`.stat` | Allowable values are "min", "max", "mean", "sum", "sd", and "var".
`.tform` | How should each feature-vector or image-vector be transformed before summarization?
`.as` | What class of object should be returned (`ImagingExperiment` or `DataFrame`)?
`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", .as="DataFrame")

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

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

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

[Package Cardinal version 2.4.0 Index]