[R] sort file names in numerical order

Gabor Grothendieck ggrothendieck at gmail.com
Sat Jul 17 14:33:57 CEST 2010


On Sat, Jul 17, 2010 at 4:31 AM, Sebastian Gibb <lists at sebastiangibb.de> wrote:
> Hello,
>
> I get some file names by list.files().
> These names are in alphabetical order.
> I want to change it to logical numeric order.
> Example:
>> fileNames <- c("A10", "A1", "A2", "B1", "B2", "B10")
>> sort(fileNames)
> [1] "A1"  "A10" "A2"  "B1"  "B10" "B2"
> I want to have:
> "A1"  "A2" "A10" "B1" "B2" "B10"
>
> Is this possible?
>

The code for mixsort which does that type of sorting can be found on this page:

  http://gsubfn.googlecode.com

and gtools has a mixedsort function.



More information about the R-help mailing list