| apply_by_groups | R Documentation |
Applies a function to groups defined by a metadata variable.
apply_by_groups(
dataset,
metadata.var,
fn.to.apply = "mean",
variables = NULL,
variable.bounds = NULL
)
dataset |
Dataset to analyze. |
metadata.var |
Metadata variable used to define groups. |
fn.to.apply |
Function to apply. |
variables |
Variables to include. |
variable.bounds |
Optional numeric bounds for variables. |
A matrix-like object with one row per selected variable and one column per group defined by 'metadata.var'. Each cell contains the result of applying 'fn.to.apply' to the values of that variable within the corresponding group.
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_groups(dataset, "group", mean)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.