'<'使用有序因素时会产生误导

时间:2014-12-14 20:44:58

标签: r

在尝试使用有序因子的一些事情时,我观察到在给予ordered = TRUE时,输出的打印顺序与命令中提到的级别相同。见下文。

> data = c("yes","yes","no","maybe","maybe","maybe")
> fac = factor(data,levels=c("yes","no","maybe"),ordered = T)
> table(fac)
fac
  yes    no maybe 
    2     1     3 
> fac = factor(data,levels=c("no","yes","maybe"),ordered = T)
> table(fac)
fac
   no   yes maybe 
    1     2     3 
> fac = factor(data,levels=c("maybe","yes","no"),ordered = T)
> table(fac)
fac
maybe   yes    no 
    3     2     1 

我在这里有两个问题 那么,有序这个词是指在给定的水平基础上进行排序?然后我怎么按照计数的升序打印出来,即“no”后跟“yes”后跟“maybe”

  1. 如果没有考虑计数,那么符号'<'表示?它给出了错误的印象,即计数为<也许<是的,这不是真的。

      

    fac = factor(data,levels = c(“no”,“maybe”,“yes”),ordered = T)

         

    FAC   [1]是的,不,也许也许可能       级别:否<也许<是

  2. ordered = T需要等级,(因为它基本上是根据等级订购的)。当我们尝试使用ordered = T而不指定级别时,你不认为它应该抛出错误吗?我们是否只是假设默认级别是级别的字母顺序?

0 个答案:

没有答案