column.cut: Cut numeric column and assign labels to bins

Description Usage Arguments Value Examples

View source: R/cut.column.R

Description

Cuts a numeric column using Hmisc::cut2 and optionally assigns different labels to the levels produced. If labels are provided, there must be as many of them as there are levels.

Usage

1
column.cut(x, field, cuts, labels = NULL)

Arguments

x

input data frame

field

name of numeric column in x to cut

cuts

cut points. If cuts does not cover the range of the data, then extra bins will be returned on the ends.

labels

optional character vector of level labels. If used, must be same length as the factor produced.

Value

factor with binned values for x[[field]] and the names from labels

Examples

1
2
3
4
5
med.inc <- acs.median(wa.house16, 'HINCP')
cuts <- med.inc * c(0.3, 0.5, 0.8, 1.2)
labels <- c('0-30 AMI', '30-50 AMI', '50-80 AMI', '80-120 AMI', '>120 AMI')
wa.house16$Income.Band <- column.cut(wa.house16, 'HINCP', cuts=cuts, labels=labels)
group.count(wa.house16, 'Income.Band', drop.na.group=TRUE)

davidthaler/PUMSutils documentation built on July 13, 2019, 9:58 a.m.