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: eq (default) (equal wide intervals), yes (wider intervals at higher values of x), no (wider intervals at lower values of x), avg (wider intervals near the mean of x).

q

Extension factor. Tells how much is each next interval wider then the previous one. Not used when type="eq".

k

Number of classes.

r

Minimum and maximum values to define intervals of x. Default are minimum and maximum values of x.

num

If TRUE (default) numerical values are returned, otherwise intervals are returned.

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'")

[Package multiUS version 1.2.3 Index]