ExtractSelection: ** RESERVED FOR INTERNAL USE **

View source: R/z_matrixes.R

ExtractSelectionR Documentation

** RESERVED FOR INTERNAL USE **

Description

Extract and rename matrix columns.

Usage

ExtractSelection(M, cols, rows = NULL, meta = NULL)

Arguments

M

matrix.

cols

list.

rows

optional.

meta

optional data.frame.

Value

ExtractSelection returns a matrix.

Examples


meta <- data.frame(
  antibody  = gl(2, 2, 8, labels = c("H3", "IgG")),
  genotype  = gl(2, 1, 8, labels = c("WT", "mutant")),
  replicate = gl(2, 4, 8, labels = c("R1", "R2"))
)
rownames(meta) <- apply(meta, 1, paste, collapse = "_")
M <- matrix(1:80, 10, 8, dimnames = list(NULL, rownames(meta)))
n <- ncol(M)

# Column selection by name or with logical expression on metadata
ExtractSelection(
  M, meta = meta, cols = list(
    x = antibody == "H3"  & genotype == "WT", y = c("IgG_WT_R1", "IgG_WT_R2")
  )
)
ExtractSelection(
  M, meta = meta, cols = list(
    x = c("H3_WT_R1", "H3_WT_R2"), y = antibody == "IgG" & genotype == "WT"
  )
)

# Internal order of extracted columns is determined by metadata
ExtractSelection(
  M[, n:1], meta = meta[1:n, ], cols = list(
    x = antibody == "H3"  & genotype == "WT",
    y = antibody == "IgG" & genotype == "WT"
  )
)
ExtractSelection(
  M[, 1:n], meta = meta[n:1, ], cols = list(
    x = antibody == "H3"  & genotype == "WT",
    y = antibody == "IgG" & genotype == "WT"
  )
)

benja0x40/Barbouille documentation built on March 26, 2023, 11:38 p.m.