shrink_df: Shrink data.frame by group

shrink_dfR Documentation

Shrink data.frame by group

Description

Shrink data.frame by group

Usage

shrink_df(
  df,
  by,
  string_func = jamba::cPasteU,
  num_func = mean,
  extra_funcs = NULL,
  do_test = FALSE,
  verbose = FALSE,
  ...
)

Details

This function condenses a data.frame by groups of rows, applying an appropriate function to character columns, and numeric columns. It is intended to be a simple but configurable tool for the majority of scenarios.

This function uses data.table for overall speed.

See Also

Other venndir utility: curate_venn_labels(), expand_range(), make_color_contrast(), make_venn_combn_df(), make_venn_test(), match_list(), nudge_venndir_label(), print_color_df(), three_point_angle(), venndir_legender(), venndir_to_df()

Examples

testdf <- data.frame(check.names=FALSE,
   SYMBOL=rep(c("ACTB", "GAPDH", "PPIA"), c(2, 3, 1)),
   `logFC B-A`=c(1.4, 1.4, 2.3, NA, 2.3, 5.1),
   probe=paste0("probe", 1:6))
shrink_df(testdf, by="SYMBOL", num_func=function(x){mean(x, na.rm=TRUE)})

testdftall <- do.call(rbind, lapply(1:10000, function(i){
   idf <- testdf;
   idf$SYMBOL <- paste0(idf$SYMBOL, "_", i);
   idf;
}))
head(testdftall, 12)
shrunk_tall <- shrink_df(testdftall,
   by="SYMBOL",
   num_func=function(x){mean(x, na.rm=TRUE)})

shrunk_tall2 <- jamses::shrinkDataFrame(testdftall,
   groupBy="SYMBOL")
head(shrunk_tall2, 12)


jmw86069/venndir documentation built on Nov. 14, 2024, 10:12 a.m.