scale_by_variable: Expand variables in a data frame via contextualized or named...

Description Usage Arguments Value Examples

Description

Expand variables in a data frame via contextualized or named conceptual scaling

Usage

1
2
3

Arguments

data

Data frame.

var

Character. The name of the column of data that scale scales.

scale

Binary numeric matrix or character. The scale to use to transform var, either as a formal context (binary matrix) or as a standard type (passed to make_scale_standard).

vars

Character vector. The names of the columns of data that scales scale.

scales

List having the same length as vars containing the scales to transform vars.

Value

A binary matrix (formal context).

Examples

 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)

corybrunson/context documentation built on May 13, 2019, 10:52 p.m.