How to perform natural (lexicographic) sorting in R? [duplicate]

I don’t think “alphanumeric sort” means what you think it means. In any case, looks like you want mixedsort, part of gtools. > install.packages(‘gtools’) […] > require(‘gtools’) Loading required package: gtools > n [1] “abc21” “abc2” “abc1” “abc01” “abc4” “abc201” “1b” “1a” > mixedsort(n) [1] “1a” “1b” “abc1” “abc01” “abc2” “abc4” “abc21” “abc201”

Javascript : natural sort of alphanumerical strings

This is now possible in modern browsers using localeCompare. By passing the numeric: true option, it will smartly recognize numbers. You can do case-insensitive using sensitivity: ‘base’. Tested in Chrome, Firefox, and IE11. Here’s an example. It returns 1, meaning 10 goes after 2: ’10’.localeCompare(‘2’, undefined, {numeric: true, sensitivity: ‘base’}) For performance when sorting large … Read more

Natural Sort Order in C#

The easiest thing to do is just P/Invoke the built-in function in Windows, and use it as the comparison function in your IComparer: [DllImport(“shlwapi.dll”, CharSet = CharSet.Unicode)] private static extern int StrCmpLogicalW(string psz1, string psz2); Michael Kaplan has some examples of how this function works here, and the changes that were made for Vista to … Read more