Why does `cut` object to my labels?

后端 未结 1 1063
旧时难觅i
旧时难觅i 2021-01-19 19:50

I am trying to label values based on the range they fall into, the way you might with, say, grading assignments. So if I have a data frame of mean quiz scores, and a data fr

相关标签:
1条回答
  • 2021-01-19 20:21

    The breaks vector has to be one element longer than the labels vector: you need both a lower and an upper cutoff for each category. Just tack 100 (upper limit) onto the end of the breaks vector (might need to be 100.5 if you have any scores of exactly 100 ...) As pointed out in the comment above, you should have your breaks in ascending order ...

    cut(grades$Mean, 
        breaks = c(rev(letters$Cutoff),100),
        labels = rev(letters$Letter),
        right = FALSE)
    ## [1] A B B C F
    ## Levels: F D C B A
    
    0 讨论(0)
提交回复
热议问题