order alphanumeric values from a list
Usage
mmixedOrder(
...,
decreasing = FALSE,
blanksFirst = TRUE,
na.last = NAlast,
keepNegative = FALSE,
keepInfinite = FALSE,
keepDecimal = FALSE,
ignore.case = TRUE,
useCaseTiebreak = TRUE,
sortByName = FALSE,
NAlast = TRUE,
honorFactor = TRUE,
verbose = FALSE,
matrixAsDF = TRUE
)Arguments
- ...
arguments treated as a
listof vectors to be ordered in proper order, based upon the mechanism bybase::order(), and as suchdata.frameis equivalent to alist.- decreasing
logical, default FALSE, used to reverse the sort order.- blanksFirst, na.last, keepNegative, keepInfinite, keepDecimal, ignore.case, useCaseTiebreak, sortByName
arguments passed to
mixedOrder(), exceptsortByNamewhich is not passed along.- NAlast
logicaldeprecated in favor of argumentna.lastfor consistency withbase::sort().- honorFactor
logical, default TRUE, used to enforce factor level sort order, when FALSE it sorts ascharacter.- verbose
logicalindicating whether to print verbose output, passed asverbose - 1tomixedOrder().- matrixAsDF
logicalif...supplies only one matrix object, thenmatrixAsDF=TRUEwill cause it to be converted to adata.frame, then coerce to alistbefore processing. By default, in the event only one matrix object is supplied, this conversion is performed, in order to define a sort order based upon each column in order, consistent with behavior ofdata.frameinput.
Details
This function is a minor extension to mixedOrder(),
"multiple mixedOrder()",
which accepts list input, similar to how base::order() operates.
This function is mainly useful when sorting something like a
data.frame, where ties in column 1 should be maintained then
broken by non-equal values in column 2, and so on.
This function essentially converts any non-numeric column
to a factor, whose levels are sorted using mixedOrder().
That factor is converted to numeric value, multiplied by -1
when decreasing=TRUE. Finally the list of numeric vectors
is passed to base::order().
In fact, mixedSortDF() calls this mmixedOrder() function,
in order to sort a data.frame properly by column.
See mixedOrder() and mixedSort() for a better
description of how the sort order logic operates.
See also
Other jam sort functions:
mixedOrder(),
mixedSort(),
mixedSortDF(),
mixedSorts()
Examples
# test factor level order
factor1 <- factor(c("Cnot9", "Cnot8", "Cnot10"))
sort(factor1)
#> [1] Cnot10 Cnot8 Cnot9
#> Levels: Cnot10 Cnot8 Cnot9
mixedSort(factor1)
#> [1] Cnot8 Cnot9 Cnot10
#> Levels: Cnot10 Cnot8 Cnot9
factor1[mixedOrder(factor1)]
#> [1] Cnot8 Cnot9 Cnot10
#> Levels: Cnot10 Cnot8 Cnot9
factor1[mixedOrder(factor1, honorFactor=FALSE)]
#> [1] Cnot8 Cnot9 Cnot10
#> Levels: Cnot10 Cnot8 Cnot9
factor1[mixedOrder(factor1, honorFactor=TRUE)]
#> [1] Cnot10 Cnot8 Cnot9
#> Levels: Cnot10 Cnot8 Cnot9
factor1[mmixedOrder(list(factor1))]
#> [1] Cnot10 Cnot8 Cnot9
#> Levels: Cnot10 Cnot8 Cnot9
factor1[mmixedOrder(list(factor1), honorFactor=FALSE)]
#> [1] Cnot8 Cnot9 Cnot10
#> Levels: Cnot10 Cnot8 Cnot9
factor1[mmixedOrder(list(factor1), honorFactor=TRUE)]
#> [1] Cnot10 Cnot8 Cnot9
#> Levels: Cnot10 Cnot8 Cnot9