gpt4 book ai didi

R - 你能按字母顺序比较哪个值是第一个吗?

转载 作者:行者123 更新时间:2023-12-02 05:36:20 25 4
gpt4 key购买 nike

如果我有以下值:

x <- 'random'
y <- 'word'
我可以做一个测试,看看 x 按字母顺序是在 y 之前还是之后?在这个例子中,类似于一个函数,它会产生:

alphabetical(x,y) -> True

alphabetical(y,x) -> False

最佳答案

内置的比较运算符在字符串上工作正常。

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

关于R - 你能按字母顺序比较哪个值是第一个吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41814158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com