问题描述
我有一些复杂的代码,但是我没有向您展示这一点,而是要提取问题的本质.
I have some complicated code, but instead of showing you that, I am going to extract the essence of the problem.
评估:"dogs" < "cats"
…这应该评估为FALSE
,在R 3.6中也是如此.
Evaluate: "dogs" < "cats"
… This should evaluate to FALSE
and it does in R 3.6.
求值:"Dogs" < "cats"
…这应该求值为TRUE
,因为"D"的ASCII码为68,而"c"的ASCII码为99. 99,"Dogs" < "cats"
应该计算为TRUE
,但在R 3.6.0中则不这样.但是,当我尝试使用 https://datacamp.com 网站上的控制台窗口时,表达式"Dogs" < "cats"
返回了TRUE
和表达式"dogs" < "Cats"
返回FALSE
-符合预期.
Evaluate: "Dogs" < "cats"
… This should evaluate to TRUE
because the ASCII code for "D" is 68 and the ASCII code for "c" is 99. Since 68 < 99, "Dogs" < "cats"
should evaluate to TRUE
, but it does not in R 3.6.0. However, when I tried using the Console window on the https://datacamp.com website, the expression "Dogs" < "cats"
returned TRUE
and the expression "dogs" < "Cats"
returned FALSE
- as expected.
因此,我的问题是,为什么R 3.6.0为("Dogs" < "cats"
)返回FALSE
?
Hence, my question is, why does R 3.6.0 return FALSE
for ("Dogs" < "cats"
) ?
推荐答案
DataCamp的解释器显示:
The interpreter at DataCamp shows:
> Sys.getlocale()
[1] "C"
而我的,也许是你的:
> Sys.getlocale()
[1] "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8"
在"C"语言环境下,字符将按其ascii值进行比较,而对于en_US.UTF-8,它们将使用aAbBcC,依此类推.
With the "C" locale, characters are compared by their ascii values, whereas for en_US.UTF-8, they go aAbBcC and so on.
如评论中所述,这在关系运算符的文档中有进一步的解释:
As mentioned in the comments, this is explained further in the documentation for relational operators:
这篇关于为什么R 3.6.0在评估表达式("Dogs" <"cats")时返回FALSE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!