shrink_matrix: Shrink a numeric matrix by groups of rows

shrink_matrixR Documentation

Shrink a numeric matrix by groups of rows

Description

Shrink a numeric matrix across groups of rows, by applying a summary function.

Usage

shrink_matrix(
  x,
  groupBy,
  shrink_func = function(x) {
     mean(x, na.rm = TRUE)
 },
  return_class = c("data.frame", "matrix"),
  verbose = FALSE,
  ...
)

Arguments

x

numeric matrix

groupBy

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

shrink_func

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

return_class

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 to use the amazingly fast data.table package, with the ability to provide a custom function to shrink row values.

The default function uses mean(x, na.rm=TRUE) so that NA values are ignored where possible.

This function applies the same shrink_func to all columns, and it optimal for numeric values. For more control over which function to apply to specific columns, see shrinkDataFrame().

Trivia: This function is identical to splicejam::shrinkDataFrame() except that the default shrink_func includes na.rm=TRUE and no longer calls the .Internal() function, since that is not permitted by CRAN package guidelines.

Value

data.frame or matrix based upon argument return_class.

See Also

Other jamses utilities: choose_annotation_colnames(), contrast2comp_dev(), fold_to_log2fold(), intercalate(), list2im_opt(), log2fold_to_fold(), make_block_arrow_polygon(), mark_stat_hits(), matrix_normalize(), point_handedness(), point_slope_intercept(), shortest_unique_abbreviation(), shrinkDataFrame(), shrink_df(), sort_samples(), strsplitOrdered(), sub_split_vector(), update_function_params(), update_list_elements()


jmw86069/jamses documentation built on Nov. 4, 2024, 9:25 p.m.