[心得] sort CharacterVector

作者: Wush978 (拒看低質媒體)   2014-01-09 13:05:03
[關鍵字]: R, string, sort
[重點摘要]:
今天踩到地雷了。
我寫了一個script,在Rstudio和console下的行為卻不同,經過一兩天的debug才發現:
```r
a <- c(letters, LETTERS) # 英文的大小寫字母
sort(a)
```
的結果會和系統環境有關!!
在sort的說明文件中有:
```
The sort order for character vectors will depend on the collating sequence of the locale in use: see Comparison. The sort order for factors is the order of their levels (which is particularly appropriate for ordered factors).
```
例如:http://rpubs.com/wush978/sorting
FYI
作者: clickhere (It's time to go home.)   2014-01-09 13:16:00
?Comparison的Details第二段才是解.因底層好像是qsort的樣子,得自定比較法.
作者: Wush978 (拒看低質媒體)   2014-01-09 13:25:00
謝謝補充

Links booklink

Contact Us: admin [ a t ] ucptt.com