stats::reorder 与 Hmisc::reorder
我试图解决 stats::reorder
与 Hmisc::reorder
的奇怪重叠。
在没有加载 Hmisc
的情况下,我得到了我想要的结果,即无序因子:
> with(InsectSprays, reorder(spray, count, median))
[1] A A A A A A A A A A A A B B B B B B B B B B B B C C C C C C C C C C C C D D
[39] D D D D D D D D D D E E E E E E E E E E E E F F F F F F F F F F F F
attr(,"scores")
A B C D E F
14.0 16.5 1.5 5.0 3.0 15.0
Levels: C E D A F B
现在加载 Hmisc
后,结果是一个有序因子:
> library(Hmisc)
Loading required package: survival
Loading required package: splines
Attaching package: 'Hmisc'
The following object(s) are masked from 'package:survival':
untangle.specials
The following object(s) are masked from 'package:base':
format.pval, round.POSIXt, trunc.POSIXt, units
> with(InsectSprays, reorder(spray, count, median))
[1] A A A A A A A A A A A A B B B B B B B B B B B B C C C C C C C C C C C C D D
[39] D D D D D D D D D D E E E E E E E E E E E E F F F F F F F F F F F F
Levels: C < E < D < A < F < B
在调用 stats::reorder< /code> 直接,我现在由于某种原因得到了一个有序因子。
> with(InsectSprays, stats::reorder(spray, count, median))
[1] A A A A A A A A A A A A B B B B B B B B B B B B C C C C C C C C C C C C D D
[39] D D D D D D D D D D E E E E E E E E E E E E F F F F F F F F F F F F
Levels: C < E < D < A < F < B
指定我需要一个无序因子会导致错误提示未使用 stats::reorder
?
> with(InsectSprays, stats::reorder(spray, count, median, order = FALSE))
Error in FUN(X[[1L]], ...) : unused argument(s) (order = FALSE)
所以问题实际上是如何在加载 Hmisc 的情况下获得无序因子?
I am trying to get around the strange overlap of stats::reorder
vs Hmisc::reorder
.
Without Hmisc
loaded I get the result I want, i.e. an unordered factor:
> with(InsectSprays, reorder(spray, count, median))
[1] A A A A A A A A A A A A B B B B B B B B B B B B C C C C C C C C C C C C D D
[39] D D D D D D D D D D E E E E E E E E E E E E F F F F F F F F F F F F
attr(,"scores")
A B C D E F
14.0 16.5 1.5 5.0 3.0 15.0
Levels: C E D A F B
Now after loading Hmisc
the result is an ordered factor:
> library(Hmisc)
Loading required package: survival
Loading required package: splines
Attaching package: 'Hmisc'
The following object(s) are masked from 'package:survival':
untangle.specials
The following object(s) are masked from 'package:base':
format.pval, round.POSIXt, trunc.POSIXt, units
> with(InsectSprays, reorder(spray, count, median))
[1] A A A A A A A A A A A A B B B B B B B B B B B B C C C C C C C C C C C C D D
[39] D D D D D D D D D D E E E E E E E E E E E E F F F F F F F F F F F F
Levels: C < E < D < A < F < B
In calling stats::reorder
directly, I now for some reason get an ordered factor.
> with(InsectSprays, stats::reorder(spray, count, median))
[1] A A A A A A A A A A A A B B B B B B B B B B B B C C C C C C C C C C C C D D
[39] D D D D D D D D D D E E E E E E E E E E E E F F F F F F F F F F F F
Levels: C < E < D < A < F < B
Specifying, that I would need an unordered factor results in an error suggesting that stats::reorder
is not used?
> with(InsectSprays, stats::reorder(spray, count, median, order = FALSE))
Error in FUN(X[[1L]], ...) : unused argument(s) (order = FALSE)
So the question really is how do I get an unordered factor with Hmisc loaded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过
注意 stats::reorder 是一个“调度程序”来完成,因此在您的示例中
最终调用 Hmisc::reorder.factor 而不是 stats::reorder.default。
you can do by
note that stats::reorder is a 'dispatcher' so in your example
finally Hmisc::reorder.factor is called instead of stats::reorder.default.