Bins the values of a variable (typically a factor)
Tool to easily group the values of a given variable.
bin(x, bin)
x | 
 A vector whose values have to be grouped. Can be of any type but must be atomic.  | 
bin | 
 A list of values to be grouped, a vector, or the special value   | 
It returns a vector of the same length as x
data(airquality)
month_num = airquality$Month
table(month_num)
# Grouping the first two values
table(bin(month_num, 5:6))
# ... plus changing the name to '10'
table(bin(month_num, list("10" = 5:6)))
# ... and grouping 7 to 9
table(bin(month_num, list("g1" = 5:6, "g2" = 7:9)))
# Grouping every two months
table(bin(month_num, "bin::2"))
# ... every 2 consecutive elements
table(bin(month_num, "!bin::2"))
# ... idem starting from the last one
table(bin(month_num, "!!bin::2"))
#
# with non numeric data
#
month_lab = c("may", "june", "july", "august", "september")
month_fact = factor(month_num, labels = month_lab)
# Grouping the first two elements
table(bin(month_fact, c("may", "jun")))
# ... using regex
table(bin(month_fact, "@may|jun"))
# ...changing the name
table(bin(month_fact, list("spring" = "@may|jun")))
# Grouping every 2 consecutive months
table(bin(month_fact, "!bin::2"))
# ...idem but starting from the last
table(bin(month_fact, "!!bin::2"))Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.