discretize {multiUS} | R Documentation |
Transform continuous variable to a discrete variable
Description
The function transforms a continuous variable to a k
-point discrete variable (similar to a Likert-item type variable). Different styles of answering to a survey are possible.
Usage
discretize(x, type = "eq", q = 1.5, k = 5, r = range(x), num = TRUE)
Arguments
x |
Vector with values to be transformed. |
type |
Type of transformation. Possible values are: |
q |
Extension factor. Tells how much is each next interval wider then the previous one. Not used when |
k |
Number of classes. |
r |
Minimum and maximum values to define intervals of |
num |
If |
Value
Transformed values are organized into a vector.
Author(s)
Aleš Žiberna
Examples
x <- rnorm(1000)
hist(x = discretize(x, type = "eq"), breaks = 0:5+0.5, xlab = "answer", main = "type = 'eq'")
hist(x = discretize(x, type = "yes"), breaks = 0:5+0.5, xlab = "answer", main = "type = 'yes'")
hist(x = discretize(x, type = "no"), breaks = 0:5+0.5, xlab = "answer", main = "type = 'no'")
hist(x = discretize(x, type = "avg"), breaks = 0:5+0.5, xlab = "answer", main = "type = 'avg'")