看板 R_Language 關於我們 聯絡資訊
[關鍵字]: 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 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.56.60
clickhere:?Comparison的Details第二段才是解. 01/09 13:16
clickhere:因底層好像是qsort的樣子,得自定比較法. 01/09 13:17
Wush978:謝謝補充 01/09 13:25