View source: R/fix_functions.R
fix_levels | R Documentation |
Fixes levels of a factor
fix_levels(
data,
factor_name,
method = "dl",
levels = NULL,
plot = FALSE,
k = ifelse(!is.null(levels), length(levels), 2),
track = TRUE,
...
)
data |
data.frame with the factor to fix |
factor_name |
Name of the factor to fix (as character) |
method |
Method from stringdist package to estimate distances |
levels |
Optional vector with the levels names. If "auto", levels are assigned based on frequency |
plot |
Optional: Plot cluster dendrogram? |
k |
Number of levels for clustering |
track |
Keep track of changes? |
... |
Further parameters passed to stringdist::stringdistmatrix function |
mydata <- data.frame(factor1=factor(c("Control", "Treatment", "Tretament", "Tratment", "treatment",
"teatment", "contrl", "cntrol", "CONTol", "not available", "na")))
fix_levels(mydata, "factor1", k=4, plot=TRUE) #Chose k to select matching levels
fix_levels(mydata, "factor1", levels=c("Control", "Treatment"), k=4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.