make_numeric | R Documentation |
This function converts a character or factor column into numeric codes, preserving numeric columns as-is. Character and factor variables are first converted to factors and then assigned numeric codes based on their levels.
make_numeric(col)
col |
A vector (column) to be converted. It can be a character, factor, or numeric vector. |
A numeric vector. If the input is a character or factor column, it is converted to numeric codes. Numeric columns are returned unchanged.
# Example usage
char_col <- c("a", "b", "a", "c")
factor_col <- factor(c("low", "medium", "high"))
numeric_col <- c(1.2, 3.4, 5.6)
# Convert columns to numeric codes
make_numeric(char_col) # Returns numeric codes for characters
make_numeric(factor_col) # Returns numeric codes for factors
make_numeric(numeric_col) # Returns numeric values unchanged
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.