View source: R/synthetic_data_perturbation.R
| detect_variable_types | R Documentation |
Analyzes a data frame to automatically classify variables as continuous or categorical, and returns a subset of the data with specified variables excluded.
detect_variable_types(data, max_unique_for_cat = 10, exclude_vars = NULL)
data |
A data frame to analyze |
max_unique_for_cat |
Integer. Maximum number of unique values for a numeric variable to be considered categorical. Default is 10. |
exclude_vars |
Character vector of variable names to exclude from both classification and the returned dataset (e.g., ID variables, timestamps). Default is NULL. |
The function classifies variables using the following rules:
Numeric variables with more than max_unique_for_cat unique values
are classified as continuous
Numeric variables with max_unique_for_cat or fewer unique values
are classified as categorical
Factor, character, and logical variables are always classified as categorical
Variables listed in exclude_vars are omitted from classification
and removed from the returned dataset
A list containing:
continuous_vars |
Character vector of variable names classified as continuous |
cat_vars |
Character vector of variable names classified as categorical |
data_subset |
Data frame with exclude_vars columns removed |
## Not run:
example_data <- data.frame(
id = 1:100,
age = rnorm(100, 50, 10),
grade = sample(1:3, 100, replace = TRUE),
status = sample(c("Active", "Inactive"), 100, replace = TRUE),
score = runif(100, 0, 100)
)
result <- detect_variable_types(example_data,
max_unique_for_cat = 10,
exclude_vars = "id")
result$continuous_vars # c("age", "score")
result$cat_vars # c("grade", "status")
names(result$data_subset) # c("age", "grade", "status", "score")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.