mixedSorts | R Documentation |
sort alphanumeric values within a list format
mixedSorts(
x,
blanksFirst = TRUE,
na.last = NAlast,
keepNegative = FALSE,
keepInfinite = TRUE,
keepDecimal = FALSE,
ignore.case = TRUE,
useCaseTiebreak = TRUE,
sortByName = FALSE,
na.rm = FALSE,
verbose = FALSE,
NAlast = TRUE,
honorFactor = TRUE,
xclass = NULL,
indent = 0,
debug = FALSE,
...
)
x |
|
blanksFirst |
|
na.last |
|
keepNegative |
|
keepInfinite |
|
keepDecimal |
|
ignore.case |
|
useCaseTiebreak |
|
sortByName |
|
verbose |
|
NAlast |
|
xclass |
|
indent |
|
... |
additional parameters are sent to |
This function is an extension to mixedSort()
to sort each vector
in a list. It applies the sort to the whole unlisted vector then
splits back into list form.
In the event the input is a nested list of lists, only the first
level of list structure is maintained in the output data. For
more information, see rlengths()
which calculates the recursive
nested list sizes. An exception is when the data contained in x
represents multiple classes, see below.
When data in x
represents multiple classes, for example character
and factor
, the mechanism is slightly different and not as well-
optimized for large length x
. The method uses
rapply(x, how="replace", mixedSort)
which recursively, and iteratively,
calls mixedSort()
on each vector, and therefore returns data in the
same nested list
structure as provided in x
.
When data in x
represents only one class, data is unlist()
to one
large vector, which is sorted with mixedSort()
, then split back into
list
structure representing x
input.
Other jam sort functions:
mixedOrder()
,
mixedSortDF()
,
mixedSort()
,
mmixedOrder()
Other jam string functions:
asSize()
,
breaksByVector()
,
cPasteSU()
,
cPasteS()
,
cPasteUnique()
,
cPasteU()
,
cPaste()
,
fillBlanks()
,
formatInt()
,
gsubOrdered()
,
gsubs()
,
makeNames()
,
mixedOrder()
,
mixedSortDF()
,
mixedSort()
,
mmixedOrder()
,
nameVectorN()
,
nameVector()
,
padInteger()
,
padString()
,
pasteByRowOrdered()
,
pasteByRow()
,
sizeAsNum()
,
tcount()
,
ucfirst()
,
uniques()
Other jam list functions:
cPasteSU()
,
cPasteS()
,
cPasteUnique()
,
cPasteU()
,
cPaste()
,
heads()
,
jam_rapply()
,
list2df()
,
mergeAllXY()
,
rbindList()
,
relist_named()
,
rlengths()
,
sclass()
,
sdim()
,
uniques()
,
unnestList()
# set up an example list of mixed alpha-numeric strings
set.seed(12);
x <- paste0(sample(letters, replace=TRUE, 52), rep(1:30, length.out=52));
x;
# split into a list as an example
xL <- split(x, rep(letters[1:5], c(6,7,5,4,4)));
xL;
# now run mixedSorts(xL)
# Notice "e6" is sorted before "e30"
mixedSorts(xL)
# for fun, compare to lapply(xL, sort)
# Notice "e6" is sorted after "e30"
lapply(xL, sort)
# test super-long list
xL10k <- rep(xL, length.out=10000);
names(xL10k) <- as.character(seq_along(xL10k));
print(head(mixedSorts(xL10k), 10))
# Now make some list vectors into factors
xF <- xL;
xF$c <- factor(xL$c)
# for fun, reverse the levels
xF$c <- factor(xF$c,
levels=rev(levels(xF$c)))
xF
mixedSorts(xF)
# test super-long list
xF10k <- rep(xF, length.out=10000);
names(xF10k) <- as.character(seq_along(xF10k));
print(head(mixedSorts(xF10k), 10))
# Make a nested list
set.seed(1);
l1 <- list(
A=sample(nameVector(11:13, rev(letters[11:13]))),
B=list(
C=sample(nameVector(4:8, rev(LETTERS[4:8]))),
D=sample(nameVector(LETTERS[2:5], rev(LETTERS[2:5])))
)
)
l1;
# The output is a nested list with the same structure
mixedSorts(l1, verbose=TRUE);
mixedSorts(l1, sortByName=TRUE, verbose=TRUE);
# Make a nested list with two sub-lists
set.seed(1);
l2 <- list(
A=list(
E=sample(nameVector(11:13, rev(letters[11:13])))
),
B=list(
C=sample(nameVector(4:8, rev(LETTERS[4:8]))),
D=sample(nameVector(LETTERS[2:5], rev(LETTERS[2:5])))
)
)
l2;
# The output is a nested list with the same structure
mixedSorts(l2);
mixedSorts(l2, sortByName=TRUE);
# when one entry is missing
L0 <- list(A=3:1,
B=list(C=c(1:3,NA,0),
D=LETTERS[c(4,5,2)],
E=NULL));
L0
mixedSorts(L0)
mixedSorts(L0, na.rm=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.