How do I create binned factor variables from a continuous variable, with custom breaks?

后端 未结 2 859
你的背包
你的背包 2020-12-15 10:26

I have a vector that looks like this:

dataset <- c(4,7,9,1,10,15,18,19,3,16,10,16,12,22,2,23,16,17)

I would like to create four dummy c

2条回答
  •  情话喂你
    2020-12-15 11:13

    Use cut:

    data.frame(dataset, bin=cut(dataset, c(1,4,9,17,23), include.lowest=TRUE))
    

提交回复
热议问题