dot-replace_by_most_frequent_categories: Find Best Match: Replace Categories by the Most Frequent...

.replace_by_most_frequent_categoriesR Documentation

Find Best Match: Replace Categories by the Most Frequent Match

Description

Used for mapping identity columns across objects. This function replaces each category in a query column of a data frame with the most frequently corresponding category in a reference column. It calculates the assignment quality, reports it, and optionally plots it.

Usage

.replace_by_most_frequent_categories(
  df,
  query_col = colnames(df)[1],
  ref_col = colnames(df)[2],
  show_plot = TRUE,
  suffix_barplot = NULL,
  ext = "png",
  min.thr = 0.5,
  ...
)

Arguments

df

A data frame containing the data.

query_col

The name of the column in 'df' whose categories are to be replaced. By default, the first column of 'df' is used.

ref_col

The name of the column in 'df' used as reference for replacement. By default, the second column of 'df' is used.

show_plot

Logical, whether to plot assignment quality. Defaults to TRUE.

suffix_barplot

Suffix for barplot.

...

Additional parameters passed to the qbarplot function.

Value

A data frame with categories in 'query_col' replaced by the most frequent match from 'ref_col'.

Examples

## Not run: 
.replace_by_most_frequent_categories(df = my_data)
(MXX <- as.tibble(structure(
  c(
    "Adjut", "Adjut", "Yearn", "Adjut", "Dwarf", "Adjut",
    "Dwarf", "Adjut", "Dwarf", "Yearn", "Dwarf", "Dwarf", "Dwarf",
    "Yearn", "Dwarf", "Dwarf", "Dwarf", "Zebra", "Yucca", "Plyer",
    "Blaze", "Blaze", "Dazed", "Blaze", "Swept", "Bold", "Vixen",
    "Bold", "Swept", "Dazed", "Mirth", "Witch", "Vixen", "Dazed",
    "Swept", "Mirth", "Swept", "Vexed", "Query", "Yolk"
  ),
  .Dim = c(20L, 2L), .Dimnames =
    list(NULL, c("RNA_snn_res.0.1.ordered", "RNA_snn_res.0.3.ordered"))
)))

z <- .replace_by_most_frequent_categories(df = MXX)
head(cbind(MXX[, 1], z[, 1]))

## End(Not run)

vertesy/Seurat.utils documentation built on Dec. 4, 2024, 5:20 p.m.