# Re: [Rd] "Human-style" sort() of alphanum strings?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 07 Jan 2010 19:07:50 -0500

I had suggested two possibilities, not just mixedsort. The other was mixsort:

> mixsort("a.b.c")

[1] "a.b.c"
> print(mixsort("a"))

[1] "a"
> print(mixsort("a."))

[1] "a."
> print(mixsort("a.b"))

[1] "a.b"
> print(mixsort("a.b."))

[1] "a.b."
> print(mixsort("a.b.c"))

[1] "a.b.c"
> print(mixsort("a.b.c."))

[1] "a.b.c."

On Thu, Jan 7, 2010 at 6:50 PM, Henrik Bengtsson <hb_at_stat.berkeley.edu> wrote:
>
> mixedsort() gets confused when there are periods in the string(s);
>
>>   print(gtools::mixedsort("a"))
> [1] "a"
>>   print(gtools::mixedsort("a."))
> [1] "a." NA
>>   print(gtools::mixedsort("a.b"))
> [1] "a.b" NA    NA
>>   print(gtools::mixedsort("a.b."))
> [1] "a.b." NA     NA     NA
>>   print(gtools::mixedsort("a.b.c"))
> [1] "a.b.c" NA      NA      NA      NA
>>   print(gtools::mixedsort("a.b.c."))
> [1] "a.b.c." NA       NA       NA       NA       NA
>
> Is the '.' trigger an incorrect interpretation of a number?
>
> /Henrik
>
> On Tue, Jan 5, 2010 at 3:48 PM, Gabor Grothendieck
> <ggrothendieck_at_gmail.com> wrote:
>> See mixedsort in gtools.  Also on http://gsubfn.googlecode.com see
>> mixsort example in the section starting ### more examples
>>
>> On Tue, Jan 5, 2010 at 6:34 PM, Henrik Bengtsson <hb_at_stat.berkeley.edu> wrote:
>>> I know it is fairly easy to implement (though not always well
>>> defined), but is there an existing sort function out there that takes
>>> alphanum strings and sort them in a "human" fashion?  For example,
>>>
>>> z1.doc z10.doc z100.doc z101.doc z11.doc z2.doc
>>>
>>> it should out put:
>>>
>>> z1.doc z2.doc z10.doc z11.doc z100.doc z101.doc
>>>
>>> (from http://www.davekoelle.com/alphanum.html).
>>>
>>> /Henrik
>>>
>>> ______________________________________________
>>> R-devel_at_r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 08 Jan 2010 - 00:13:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 08 Jan 2010 - 13:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.