sorting - Sort in R with multiple criteria (alphanumeric) -


l <-  c("bc321" , "bc320", "bc100" , "da124" ,"da174" ,"da224", "da33",  "da98" ) require('gtools') mixedsort(l) "bc100" "bc320" "bc321" "da33"  "da98"  "da124" "da174" "da224" 

but want "da33" "da98" "da124" "da174" "da224" "bc100" "bc320" "bc321"

really appreciate help. thank you

here's 1 way:

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" 

check this post josh o'brien magic happening strsplit (marked ##).


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -