discretize | R Documentation |
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.
discretize(x, type = "eq", q = 1.5, k = 5, r = range(x), num = TRUE)
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 |
Transformed values are organized into a vector.
Aleš Žiberna
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'")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.