aggregate_samples: Aggregate samples

aggregate_samplesR Documentation

Aggregate samples

Description

Aggregate samples according to an aggregate function like mean, median, etc. This can be used to merge replicates.

Usage

aggregate_samples(dataset, indexes, aggreg.fn = "mean", meta.to.remove = c())

Arguments

dataset

List representing the dataset from a metabolomics experiment.

indexes

Index vector with the samples that are going to be aggregated (e.g. c(1,1,2,2), this index vector will aggregate the first two samples and the last two samples).

aggreg.fn

Aggregation function (e.g. "mean", "median", etc).

meta.to.remove

Metadata variables to be removed.

Value

A dataset object in which samples have been aggregated according to 'indexes' and 'aggreg.fn', with updated 'data', 'metadata', and preserved dataset-level fields such as labels, type, and description.

Examples

data <- matrix(
  c(1, 2, 10, 12,
    3, 4, 14, 16),
  nrow = 2,
  dimnames = list(c("x1", "x2"), c("s1", "s2", "s3", "s4"))
)
metadata <- data.frame(
  class = factor(c("A", "A", "B", "B")),
  batch = c(1, 1, 2, 2),
  row.names = c("s1", "s2", "s3", "s4")
)
dataset <- list(
  data = data,
  metadata = metadata,
  labels = list(),
  type = "example",
  description = "toy dataset"
)
aggregate_samples(dataset, c(1, 1, 2, 2), "mean")


specmine documentation built on Aug. 5, 2026, 5:06 p.m.