I have a continuous variable ranging from 0 to 1000+. However, I want to convert them into groups with the lowest value 0 as a single group.
x <- cut(x, breaks = c(0,50,100,200,500,1000)),
labels = c("0","1-50","51-100","101-199","200-499",
"500-999",">1000")
Using cut function has not been able to achieve this purpose. Is there anything that I'm missing?
You've got some issues in your call to cut
breaks
that should be there, prematurely ending the call. This should work:
x <- cut(x, breaks = c(0,50,100,200,500,1000,max(x)),labels = c("0-50","51-100","101-199","200-499","500-999", "1000+"), include.lowest = TRUE)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.