Factors in R: more than an annoyance?

后端 未结 7 1478
梦如初夏
梦如初夏 2020-11-28 19:30

One of the basic data types in R is factors. In my experience factors are basically a pain and I never use them. I always convert to characters. I feel oddly like I\'m missi

相关标签:
7条回答
  • 2020-11-28 20:19

    ordered factors are awesome, if I happen to love oranges and hate apples but don't mind grapes I don't need to manage some weird index to say so:

    d <- data.frame(x = rnorm(20), f = sample(c("apples", "oranges", "grapes"), 20, replace = TRUE, prob = c(0.5, 0.25, 0.25)))
    d$f <- ordered(d$f, c("apples", "grapes", "oranges"))
    d[d$f >= "grapes", ]
    
    0 讨论(0)
提交回复
热议问题