Data
I created the following example data for this answer:
(char_vec <- paste0("K3SG1-105-1051-", c(1:4, 10, 100, 1000)))
[1] "K3SG1-105-1051-1" "K3SG1-105-1051-2" "K3SG1-105-1051-3"
[4] "K3SG1-105-1051-4" "K3SG1-105-1051-10" "K3SG1-105-1051-100"
[7] "K3SG1-105-1051-1000"
Solution
char_vec[order(as.numeric(sub('.*-', '', char_vec)))]
[1] "K3SG1-105-1051-1" "K3SG1-105-1051-2" "K3SG1-105-1051-3"
[4] "K3SG1-105-1051-4" "K3SG1-105-1051-10" "K3SG1-105-1051-100"
[7] "K3SG1-105-1051-1000"
Explanation
sub('.*-', '', char_vec)
gets just the last number characters in the vector, which we then convert to numeric and order to order char_vec
.
If you order the characters 1, 2, and 10, the order is 1, 10, 2 because you're alphabetically ordering strings, not ordering numbers.