shrinkDataFrame | R Documentation |
Shrink data.frame by row groups
shrinkDataFrame(
x,
groupBy,
na.rm = TRUE,
string_func = function(x) jamba::cPasteSU(x, na.rm = TRUE),
num_func = function(x) {
mean(x, na.rm = TRUE)
},
add_string_cols = NULL,
num_to_string_func = as.character,
keep_na_groups = TRUE,
include_num_reps = FALSE,
collapse_method = 2,
verbose = FALSE,
...
)
x |
|
groupBy |
|
string_func |
|
num_func |
|
add_string_cols |
|
num_to_string_func |
|
keep_na_groups |
|
include_num_reps |
|
collapse_method |
|
verbose |
|
... |
additional arguments are ignored. |
Purpose is to shrink a data.frame
to have one row per row grouping.
The row grouping can use a single column of identifiers, or multiple
columns. The challenge is to apply a relevant function to each column,
expecting there will be columns with numeric
, character
, or factor
types.
The default behavior:
numeric
columns are summarized with mean(x, na.rm=TRUE)
, so that
NA values are ignored when there are non-NA values present.
character
columns are combined using unique, sorted character
strings.
This step uses jamba::cPasteSU()
where the
S
activates sorting using jamba::mixedSort()
, and
U
calls unique()
.
To retain all values, remove the U
and call jamba::cPasteS()
To skip the sort, remove the S
and call jamba::cPasteU()
To keep all values, and skip sorting, call jamba::cPaste()
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()
,
shrink_df()
,
shrink_matrix()
,
sort_samples()
,
strsplitOrdered()
,
sub_split_vector()
,
update_function_params()
,
update_list_elements()
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.5, 5.1),
probe=paste0("probe", 1:6))
shrink_df(testdf, by="SYMBOL")
shrink_df(testdf, by="SYMBOL", num_func=mean)
shrink_df(testdf, by="SYMBOL", add_string_cols="logFC B-A")
testdftall <- do.call(rbind, lapply(1:10000, function(i){
idf <- testdf;
idf$SYMBOL <- paste0(idf$SYMBOL, "_", i);
idf;
}))
shrunk_tall <- shrink_df(testdftall,
by="SYMBOL")
head(shrunk_tall, 6)
shrunk_tall2 <- jamses::shrinkDataFrame(testdftall,
groupBy="SYMBOL")
head(shrunk_tall2, 6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.