Description Usage Arguments Details Value Examples
Performs a measures aggregation by formula on a dataset
1 | aggregate_data(.data, f, id_cols = NULL, value_cols = NULL, na.rm = FALSE)
|
.data |
Dataset (data.frame), 'id' column is required. |
f |
A formula |
id_cols |
Identification columns except id (string vector or R formula, like ~y) |
value_cols |
Calculation columns (string vector or R formula, like ~y) |
na.rm |
TRUE to replace all NAs to zero |
The function transforms a dataset so measure IDs become dataframe columns and then applies a formula to calculate aggregated measures.
A formula can be a mesaure ID or any single-parameter function with aggregation operators (+. -, etc). See examples below.
If a dataset contain additional identification variables, id_cols should be provided.
A value_cols parameter specifies which variables are to be aggregated. If omitted, any numeric or logical columns are taken.
Calculation results (data.frame containing id_cols and value_cols) Results are placed to value_cols, id_cols copied without changes
1 2 3 4 5 6 7 8 9 | ## Not run:
d <- data.frame(id = c("i1", "i1", "i2", "i3"), y = c(10, 20, 10, 10), a = c(4,2,3, 1), r = c(4,5,6,7))
aggregate_data(d, f = "log(i1)+i2+i3", id_cols = ~y, value_cols = c("a", "r"), na.rm = TRUE)
d <- data.frame(id = c("i1", "i2", "i3"), a = c(4, 3, 1), r = c(4, 6,7))
aggregate_data(d, f = "i1+i2+ifelse(i3==1,0,-1)", value_cols = c("a", "r"))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.