This function converts a numeric column in a data frame to a factor variable, allowing for custom break points and grouping.
Usage
cut3(tbl, var_name, breaks, groups = NULL, bf_args = list(), .inf = FALSE, ...)
Arguments
- tbl
data.frame: The data frame containing the data to be converted.
- var_name
character: The name of the numeric variable to convert to a factor.
- breaks
numeric: Break points defining factor levels. See
See Also
section for more details.- groups
character: The name of the variable for grouping data before conversion.
- bf_args
list: Additional arguments to be passed to the break function.
- .inf
logical: Whether to extend break points with -Inf and Inf.
- ...
Additional arguments passed to
base::cut
.
See also
base::cut
, for the underlying cut function used.
vignette("cut3", package = "Dmisc")
, for examples and extended usage.
Examples
datos <- data.frame(edad = seq(1:100))
dplyr::count(cut3(datos, "edad", 5), edad)
#> edad n
#> 1 (0.901,20.8] 20
#> 2 (20.8,40.6] 20
#> 3 (40.6,60.4] 20
#> 4 (60.4,80.2] 20
#> 5 (80.2,100] 20