1

I'm trying to sort the following vector of characters based on 1) numbers and 2) characters:

"BLH-07", "BLH-08", "AFH-08", "AFH-09"

I've tried to use mixedsort, however it doesn't work at present.

library(gtools)
vector = c("BLH-07", "BLH-08", "AFH-08", "AFH-09")
sort = mixedsort(vector, decreasing = TRUE) 

My result:

"BLH-07", "BLH-08", "AFH-08", "AFH-09"

Desired result:

"BLH-07", "AFH-08", "BLH-08", "AFH-09"

-> Thus, sorting first on the numbers in the string, and next alphabetically on BLH, AFH...

Matt
  • 2,947
  • 1
  • 9
  • 21

0 Answers0