dtize_col | R Documentation |
Discretizes a numeric vector into categories based on specified cutoff points. The function handles missing values, allows for infinite bounds, and supports predefined cutoffs such as the mean or median.
dtize_col(
column,
cutoff = "median",
labels = c("low", "high"),
include_right = TRUE,
infinity = TRUE,
include_lowest = TRUE,
na_fill = "none"
)
column |
A numeric vector to discretize. |
cutoff |
A numeric vector specifying cutoff points, or a string ("mean" or "median"). |
labels |
A character vector specifying labels for the resulting categories. |
include_right |
Logical. If |
infinity |
Logical. If |
include_lowest |
Logical. If |
na_fill |
A string specifying the method to impute missing values: "none", "mean", or "median" (default "none"). |
A factor with the same length as column
, where each value is categorized based on the cutoffs.
data(BrookTrout)
# Example with predefined cutoffs
discrete_water_temp <- dtize_col(
BrookTrout$eDNAConc, cutoff=13.3,
labels=c("low", "high"),
infinity=TRUE
)
# Example with median as cutoff
discrete_pH <- dtize_col(BrookTrout$pH, cutoff="median")
# Example with missing value imputation
filled_col <- dtize_col(
c(1, 2, NA, 4, 5),
cutoff = "mean",
include_right=FALSE,
na_fill = "mean"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.