R中的data.table :: setkey如何排序?

时间:2017-08-24 18:12:28

标签: r string sorting data.table character

我在data.table包中发现setkey函数不对像base::sort函数这样的字符值进行排序。 setkey中字符排序背后的逻辑是什么,以及如何使setkeysort相互一致?

temp_dt <- data.table(index = c(letters[1:5], LETTERS[1:5]))
print(temp_dt$index)
# [1] "a" "b" "c" "d" "e" "A" "B" "C" "D" "E"

setkey(temp_dt, index)
print(temp_dt$index)
# [1] "A" "B" "C" "D" "E" "a" "b" "c" "d" "e"

sort(temp_dt$index)
# [1] "a" "A" "b" "B" "c" "C" "d" "D" "e" "E"
# different from `setkey` results.

0 个答案:

没有答案