The package gtools has the "mixedsort" method for solving this problem.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>library(gtools) | |
>x <- paste("AA_",1:24, sep="") | |
>(y <- sort(x)) | |
[1] "AA_1" "AA_10" "AA_11" "AA_12" "AA_13" "AA_14" "AA_15" "AA_16" "AA_17" "AA_18" AA_19" | |
[12] "AA_2" "AA_20" "AA_21" "AA_22" "AA_23" "AA_24" "AA_3" "AA_4" "AA_5" "AA_6" "AA_7" | |
[23] "AA_8" "AA_9" | |
>(y1 <- mixedsort(x)) | |
[1] "AA_1" "AA_2" "AA_3" "AA_4" "AA_5" "AA_6" "AA_7" "AA_8" "AA_9" "AA_10" "AA_11" | |
[12]"AA_12" "AA_13" "AA_14" "AA_15" "AA_16" "AA_17" "AA_18" "AA_19" "AA_20" "AA_21" "AA_22" | |
[23]"AA_23" "AA_24" | |
#you can use mixedorder to get the order | |
> (y1 <- order(x)) | |
[1] 1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 3 4 5 6 7 8 9 | |
> (y2 <- mixedorder(x)) | |
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
沒有留言:
張貼留言