Skip to contents

This function aggregates data by a specified subject and optional strata. It provides flexible strategies for handling metadata conflicts in replicates.

Usage

mStat_aggregate_data(
  data.obj,
  subject.var,
  strata.var = NULL,
  meta.handle.conflict = c("first", "stop", "summarise")
)

Arguments

data.obj

A list object in a format specific to MicrobiomeStat...

subject.var

A character specifying the name of the subject variable.

strata.var

A character specifying the name of the strata variable. If NULL, no stratification is performed.

meta.handle.conflict

A character string specifying how to handle conflicting metadata in replicates. Options are: - `"first"` (default): Use the metadata from the first record encountered for each group. Issues a warning about conflicts. - `"stop"`: Stop execution with an error if any metadata conflict is found. - `"summarise"`: For numeric variables, compute the mean. For non-numeric (character/factor) variables, if they are inconsistent, stop with an error. Issues a warning for summarized numeric variables.

Value

A new list object with aggregated data.

Examples

if (FALSE) { # \dontrun{
# Prepare data for the function
data(peerj32.obj)

# Call the function with the default subject variable "subject"
aggregated_data <- mStat_aggregate_data(
  data.obj = peerj32.obj,
  subject.var = "subject",
  strata.var = NULL
)

# Example with a different subject variable name
# Let's pretend the subject ID column is called "participant"
# peerj32.obj$meta.dat$participant <- peerj32.obj$meta.dat$subject
# aggregated_data_2 <- mStat_aggregate_data(
#   data.obj = peerj32.obj,
#   subject.var = "participant",
#   strata.var = "group"
# )
} # }