使用函数
sort(x)
时,其中 x
是一个字符,字母“y”会跳到中间,紧接在字母“i”之后。> letters
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t"
[21] "u" "v" "w" "x" "y" "z"
> sort(letters)
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "y" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
[21] "t" "u" "v" "w" "x" "z"
可能的原因是我所在的立陶宛使用了“立陶宛式”的字母排序方式,但我需要正常的排序方式。如何在R代码中将排序方法更改回正常?
我正在使用Win7上的R 2.15.2。
Sys.setlocale
函数来进行设置。 - JamesSys.setlocale(category="LC_COLLATE", "C"); sort(letters)
- Josh O'Brien?sort
文档中已经非常明确地记录了这种行为。不阅读文档的惩罚要比使某些内容与语言环境相关的惩罚更严重。 - Gavin Simpson