fct_cut converts numeric variables to a factor using the breaks provided. It is built on cut, but does some additional coercion before passing to cut and labels the output in more lay-friendly manner. Note that intervals in fct_cut are closed on the left (they include the lower value and exclude the higher - e.g. 1 <= .x < 2); this is the opposite of cut's default behavior.

fct_cut(.x, breaks = quantile(.x), open = FALSE, ordered = TRUE)

Arguments

.x

A numeric vector, or a object that can be coerced to one. If .x is a factor, the level labels will be coerced, not the underlying integer representation.

breaks

A numeric vector of break points for the categories of .x

open

Should the ends of breaks be treated as open or closed? In other words, should there be a category for values in .x below the lowest value of breaks (.x < min(breaks)) or above the highest value of breaks (.x >= max(breaks))? TRUE means both are open; FALSE means both are closed (the default). Behavior for each end can be controlled by passing a logical vector of length 2 where the first value controls the lower end and the second controls the upper end (e.g. open = c(FALSE, TRUE) for count data).

ordered

Should the resulting factor be ordered? Since numeric data is inherently ordered, the default is TRUE.

Value

A factor