我试图绕过stats::reorder
vs的奇怪重叠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
中,我现在由于某种原因得到了一个有序的因素。
> 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 的情况下获得无序因子?