l <- c("BC321" , "BC320", "BC100" , "DA124" ,"DA174" ,"DA224", "DA33", "DA98" )
require('gtools')
mixedsort(l)
"BC100" "BC320" "BC321" "DA33" "DA98" "DA124" "DA174" "DA224"
但我想要 “DA33”“DA98”“DA124”“DA174”“DA224”“BC100”“BC320”“BC321”
真的很感激任何帮助。 谢谢
答案 0 :(得分:2)
这是一种方式:
x <- strsplit(l, "(?<=[A-Z])(?=[0-9])", perl=TRUE) ##
v1 = sapply(x, `[[`, 1L)
v2 = as.integer(sapply(x, `[[`, 2L))
l[order(-xtfrm(v1), v2)]
# [1] "DA33" "DA98" "DA124" "DA174" "DA224" "BC100" "BC320" "BC321"
Josh O'Brien检查this post strsplit
(用##标记)发生的神奇事件。