DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Cut Allows Break Up For Continous Data

07.21.2010
| 2421 views |
  • submit to reddit
        In order to break apart continuous data such as a series of body weights into categories us cut.

Usage:
#simple
 cut(data, breaks = 4) # break the data up into four groups

#slightly more sophisticated
#Get range
range(data)
#define breaks
breaks = seq(min, max, by=n) #n = the interval size
#perform the cut and store in var
wt.cut = cut(wt, breaks)
#view in table
table(wt.cut) 
#can easily graph
barplot(table(wt.cut)
    
    Tags:
  • r