gpt4 book ai didi

R:gtools混合排序的意外自然排序

转载 作者:行者123 更新时间:2023-12-04 12:21:15 25 4
gpt4 key购买 nike

我只是在 gtools::mixedsort 中发现了一些意想不到的行为看看我的输出是如何自然排序的。
我有一个这样的例子:

aa=c("CD57","CD58","CD158","CD158b","CD158e","CD158e1","CD319","CD335")
gtools::mixedsort(aa)
我的预期结果是:
[1] "CD57"    "CD58"    "CD158"   "CD158b"  "CD158e"  "CD158e1" "CD319"
[8] "CD335"
但是我得到了这个:
[1] "CD57"    "CD58"    "CD158"   "CD158b"  "CD158e"  "CD319"   "CD335"
[8] "CD158e1"
这样对吗?是什么原因?

最佳答案

CD158e1被视为 1580在这里,因为:

>>> 158e1
1580.0
>>>
158e1是一个带有 e 的欧拉数,所以它多给一个 0 , e2会给2个额外的等等......
所以这就是为什么它被解析为列表中的最后一个。

the documentation of mixedsort 中所述:

These functions sort or order character strings containing embeddednumbers so that the numbers are numerically sorted rather than sortedby character value. I.e. "Aspirin 50mg" will come before "Aspirin100mg". In addition, case of character strings is ignored so that "a",will come before "B" and "C".

关于R:gtools混合排序的意外自然排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69388929/

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