Learn R Programming

iNZightTools (version 1.13.0)

form_class_intervals: Form Class Intervals

Description

Create categorical intervals from a numeric variable.

Usage

form_class_intervals(
  .data,
  variable,
  method = c("equal", "width", "count", "manual"),
  n_intervals = 4L,
  interval_width,
  format = "(a,b]",
  range = NULL,
  format.lowest = ifelse(isinteger, "< a", "

Value

a dataframe with an additional column with categorical class intervals

Arguments

.data

the data set

variable

name of the variable to convert

method

one of 'equal' for equal-width intervals, 'width' for intervals of a specific width, 'count' for equal-count intervals, and 'manual' to specify break points manually

n_intervals

for methods 'equal' and 'count', this is the number of intervals to create

interval_width

for method 'width', this is the width of intervals

format

the format for intervals; use 'a' and 'b' to represent the min/max of each interval, respectively.

range

the range of the data; use this to adjust the labels (e.g., for continuous data, set this to floor/ceiling of the min/max of the data to get prettier intervals). If range does not cover the range of the data, values outside will be placed into 'less than a' and 'greater than b' categories

format.lowest

values lower than the min of range will have this label format

format.highest

values higher than the max of range will have this label format

break_points

for method 'manual', specify breakpoints here (as a numeric vector)

name

the name of the new variable in the resulting data set

Author

Tom Elliott

Examples

Run this code
form_class_intervals(iris, 'Sepal.Length', 'equal', 5L)

Run the code above in your browser using DataLab