Shrink numeric matrix by groups of rows

shrinkMatrix(
  x,
  groupBy,
  shrinkFunc = function(x) {     .Internal(mean(x)) },
  returnClass = c("data.frame", "matrix"),
  verbose = FALSE,
  ...
)

Arguments

x

numeric matrix

groupBy

vector of group labels, whose length equals nrow(x). These values will become rownames in the output data.

shrinkFunc

function that takes vector input and returns vector output. The vector class can be checked, in order to call a function on numeric or character data separately, as needed.

returnClass

character string indicating the return data type, "data.frame" returns a data.frame whose first column contains entries from groups; "matrix" returns a numeric matrix whose rownames are entries from groups.

verbose

logical indicating whether to print verbose output.

Details

This function is mainly a wrapper around the very efficient functions in the data.table package, with the ability to provide a custom function to shrink row values.