form_class_intervals: Form Class Intervals

View source: R/class_intervals.R

form_class_intervalsR Documentation

Form Class Intervals

Description

This function creates categorical intervals from a numeric variable in the given dataset.

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", "<= a"),
  format_highest = "> b",
  break_points = NULL,
  name = sprintf("%s.f", variable)
)

Arguments

data

A dataset or a survey object.

variable

The name of the numeric variable to convert into intervals.

method

The method used to create intervals:

  • '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 specifies the number of intervals to create.

interval_width

For method 'width', this sets the width of the intervals.

format

The format for interval labels; 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 the 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

Label format for values lower than the min of range.

format_highest

Label format for values higher than the max of range.

break_points

For method 'manual', specify breakpoints here as a numeric vector.

name

The name of the new variable in the resulting data set.

Value

A dataframe with an additional column containing categorical class intervals.

Author(s)

Tom Elliott, Zhaoming Su

Examples

form_class_intervals(iris, "Sepal.Length", "equal", 5L)

iNZightVIT/iNZightTools documentation built on April 8, 2024, 10:25 a.m.