Skip to content
Prev 87208 / 398506 Next

Sorting alphanumerically

On Fri, 2006-02-24 at 12:54 -0600, mtb954 mtb954 wrote:
The values are being sorted by character based ordering, which may be
impacted upon by your locale.

Thus, on my system, you end up with something like the following:
[1] "g1"   "g100" "g19"  "g2"   "g3"   "g39"  "g6"


What you can do, based upon the presumption that the prefix of 'g' is
present as you describe above, is:
[1] "g1"   "g2"   "g3"   "g6"   "g19"  "g39"  "g100"


What this does is to use gsub() to strip the 'g' and then order by
numeric value.


HTH,

Marc Schwartz