R - 你能比较哪个值按字母顺序排在第一位吗?
R - Can you compare which value is first in alphabetical order?
如果我有值:
x <- 'random'
y <- 'word'
我可以做一个测试,看看按字母顺序 x 是在 y 之前还是之后吗?在此示例中,类似于将产生的函数的内容:
alphabetical(x,y) -> True
alphabetical(y,x) -> False
alphabetical <- function(x,y){x < y}
built-in 比较运算符可以很好地处理字符串。
x < y
[1] TRUE
y < x
[1] FALSE
注意帮助页面 ?Comparison
中的详细信息,或者更直观地说,?`<`
,尤其是语言环境的重要性:
Comparison of strings in character vectors is lexicographic within the strings using the collating sequence of the locale in use [...]
Beware of making any assumptions about the collation order
如果我有值:
x <- 'random'
y <- 'word'
我可以做一个测试,看看按字母顺序 x 是在 y 之前还是之后吗?在此示例中,类似于将产生的函数的内容:
alphabetical(x,y) -> True
alphabetical(y,x) -> False
alphabetical <- function(x,y){x < y}
built-in 比较运算符可以很好地处理字符串。
x < y
[1] TRUE
y < x
[1] FALSE
注意帮助页面 ?Comparison
中的详细信息,或者更直观地说,?`<`
,尤其是语言环境的重要性:
Comparison of strings in character vectors is lexicographic within the strings using the collating sequence of the locale in use [...]
Beware of making any assumptions about the collation order