Description Usage Arguments Value Examples
Expand variables in a data frame via contextualized or named conceptual scaling
1 2 3 | scale_by_variable(data, var, scale)
scale_by_variables(data, vars = names(scales), scales)
|
data |
Data frame. |
var |
Character. The name of the column of |
scale |
Binary numeric matrix or character. The scale to use to
transform |
vars |
Character vector. The names of the columns of |
scales |
List having the same length as |
A binary matrix (formal context).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | titanic_data <- as.data.frame(Titanic)
# custom scale for Class variable
class_scale <- rbind(
c(1, 1, 1, 0),
c(0, 1, 1, 0),
c(0, 0, 1, 0),
c(0, 1, 1, 1)
)
rownames(class_scale) <- levels(titanic_data$Class)
colnames(class_scale) <- paste0(">", levels(titanic_data$Class))
print(class_scale)
scale_by_variable(data = titanic_data, var = "Class", scale = class_scale)
# nominal scale for Sex variable
scale_by_variable(data = titanic_data, var = "Sex", scale = "nominal")
# ordinal scale for Age variable
scale_by_variable(data = titanic_data, var = "Age", scale = "ordinal")
# multiple scales applied at once
both_vars <- c("Class", "Sex")
sex_scale <- make_scale_standard(objs = titanic_data$Sex, scale = "nominal")
both_scales <- list(class_scale, sex_scale)
scale_by_variables(data = titanic_data, vars = both_vars, scales = both_scales)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.