aggregateCol() performs summary statistics on a specific subset of columns.

aggregateCol(data, grp, names_aggreg = NULL, FUN = sum, ...)

Arguments

data

a data frame.

grp

an integer vector, one value per data column. Integers are used to group data columns, column with the same integer will be pooled together. Any integer is a valid group, 0 indicates that the column must be unchanged, NA removes columns.

names_aggreg

column names for aggregated columns.

FUN

a function to be applied to all groups of columns.

...

further arguments to be passed to FUN.

Value

A data frame with the grouped columns.

Details

grp is an integer vector, whose length is the number of columns of the input data frame, is used to assign a group to each column that explicit the sub-setting. Furthermore columns can be either kept as is using 0 or discarded using NA.

See also

Examples

mat1 <- matrix(1:70,10) grp1 <- c(NA,0, 1, 1, 2, 2, 2) aggregateCol(mat1, grp1, FUN = mean)
#> V2 X2 X3 #> 1 11 26 51 #> 2 12 27 52 #> 3 13 28 53 #> 4 14 29 54 #> 5 15 30 55 #> 6 16 31 56 #> 7 17 32 57 #> 8 18 33 58 #> 9 19 34 59 #> 10 20 35 60