R: Assign values by interval using vectorisation

后端 未结 2 1481
自闭症患者
自闭症患者 2021-01-26 10:15

Let\'s have a numeric vector:

a <- round(runif(20, 1, 5), 0)
[1] 3 5 4 2 1 2 3 4 5 2

I need to assign values to these numbers using table li

2条回答
  •  执念已碎
    2021-01-26 10:46

    a <-  c(3, 5, 4, 2, 1, 2, 3, 4, 5, 2)
    cut(a, breaks=c(0.5, 2.5, 4.5, 10), labels=c("A", "B", "C"))
    

提交回复
热议问题