Split the elements of an ordered factor vector

strsplitOrdered(
  x,
  split = "_",
  fixed = FALSE,
  perl = FALSE,
  useBytes = FALSE,
  sortFunc = jamba::mixedSort,
  keepOrder = TRUE,
  ...
)

Arguments

x

character or factor vector.

split

character split value sent to base::strsplit().

fixed, perl, useBytes

additional arguments sent to base::split().

sortFunc

function used to sort character values when the input x is a character vector. The default jamba::mixedSort() applies alphanumeric sort.

keepOrder

logical indicating whether to keep the order of values in the input data, for example with character input the values will be ordered by the first appearance of each term.

...

additional arguments are ignored.

Value

list of factor vectors, where each factor shares the same global factor levels based upon the input data.

Details

This function performs base::strsplit() while trying to maintain the order of factor levels in the output, based upon the order of factor levels in the input data.

See also

Other jam string functions: escapeWhitespaceRegexp(), sortSamples()

Examples

# first define a vector of sample groups iGroups <- jamba::nameVector(paste(rep(c("WT", "KO"), each=6), rep(c("Control", "Treated"), each=3), sep="_")); iGroups <- factor(iGroups, levels=unique(iGroups)); iGroups;
#> WT_Control_v1 WT_Control_v2 WT_Control_v3 WT_Treated_v1 WT_Treated_v2 #> WT_Control WT_Control WT_Control WT_Treated WT_Treated #> WT_Treated_v3 KO_Control_v1 KO_Control_v2 KO_Control_v3 KO_Treated_v1 #> WT_Treated KO_Control KO_Control KO_Control KO_Treated #> KO_Treated_v2 KO_Treated_v3 #> KO_Treated KO_Treated #> Levels: WT_Control WT_Treated KO_Control KO_Treated
strsplitOrdered(iGroups, "_");
#> [[1]] #> [1] WT Control #> Levels: WT KO Control Treated #> #> [[2]] #> [1] WT Control #> Levels: WT KO Control Treated #> #> [[3]] #> [1] WT Control #> Levels: WT KO Control Treated #> #> [[4]] #> [1] WT Treated #> Levels: WT KO Control Treated #> #> [[5]] #> [1] WT Treated #> Levels: WT KO Control Treated #> #> [[6]] #> [1] WT Treated #> Levels: WT KO Control Treated #> #> [[7]] #> [1] KO Control #> Levels: WT KO Control Treated #> #> [[8]] #> [1] KO Control #> Levels: WT KO Control Treated #> #> [[9]] #> [1] KO Control #> Levels: WT KO Control Treated #> #> [[10]] #> [1] KO Treated #> Levels: WT KO Control Treated #> #> [[11]] #> [1] KO Treated #> Levels: WT KO Control Treated #> #> [[12]] #> [1] KO Treated #> Levels: WT KO Control Treated #>