I have a little problem with sorting in R in presence of character vectors. I would like to sort
x<- c("q1","q4","q40","q10")
w.r.t. the numbers 1<4<10<40 appearing in its components. I n other words, I would like to arrive at the following output
[1] "q1" "q4" "q10" "q40"
Applying sort
to x
I arrive at
sort(x)
[1] "q1" "q10" "q4" "q40"
instead (this output makes sense to me, but it is not what I would like to obtain).
I thought about removing the characters ""
and q
in each component, and then apply sort
to the resulting numeric vector. I would like to try something simpler, though. Any help is much appreciated!
I thank you all.