I have a list of data tags as strings, much like this:
data <- c("ABCD 2", "ABCD 3", "WXYZ 1", "WXYZ 5", "WXYZ 3", "WXYZ 4", "ABCD 4", "ABCD 11")
Note that some numbers, including "1", are sometimes missing. A normal sort, of course, puts the ABCD
tags before the WXYZ
tags, and then puts ABCD 11
before ABCD 2
.
I can easily overcome the numbering issue with gtools::mixedsort
. But, for reasons of problem-specific context, I also want the WXYZ
tags to come before the ABCD
ones.
For example, when data
above is sorted as I need it, it should look like this:
dataSorted <- c("WXYZ 1", "WXYZ 3", "WXYZ 4", "WXYZ 5", "ABCD 2", "ABCD 3", "ABCD 4", "ABCD 11")
Thankfully, I only need to deal with those two types of tags now, but I figure I should ask for a general solution. Is there a way to make gtools::mixedsort
do reverse alpha but normal numeric ordering? If I set decreasing = TRUE
then it also reverses all the number orders.
Right now I am just using a list to force the order, and that is not only inelegant, but since the numbers on the tags have no theoretical upper limit, it is also going to eventually break.