apply_by_group: Apply by group

apply_by_groupR Documentation

Apply by group

Description

Applies a function to the variables of samples belonging to a given group.

Usage

apply_by_group(dataset, fn.to.apply, metadata.var, var.value)

Arguments

dataset

Dataset to analyze.

fn.to.apply

Function to apply.

metadata.var

Metadata variable used to define the group.

var.value

Value or values of the metadata variable to select.

Value

A named vector or matrix, depending on the output of 'fn.to.apply', containing the values obtained by applying the function to each variable across the samples belonging to the selected group.

Examples

data <- matrix(
  c(1, 2, 3, 4, 5, 6),
  nrow = 2,
  dimnames = list(c("x1", "x2"), c("s1", "s2", "s3"))
)
metadata <- data.frame(
  group = c("control", "control", "case"),
  row.names = c("s1", "s2", "s3")
)
dataset <- list(data = data, metadata = metadata)
apply_by_group(dataset, mean, "group", "control")


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