Learn R Programming

pedometrics (version 0.6-2)

cont2cat: Continuous to categorical

Description

Convert continuous data (numeric) into categorical data (factor or integer).

Usage

cont2cat(x, breaks)

Arguments

x
Vector, data frame or matrix with the continuous data to be converted into categorical data.
breaks
Vector or list with the lower and upper limits to be used to break the continuous data into classes.

Value

  • A vector, data frame, or matrix, depending on the class of x.

Details

Breaks must be a vector if x is a vector, but a list if x is a data frame or matrix. Using a list allows breaking the data into a different number of classes.

See Also

cut2

Examples

Run this code
require(Hmisc)
# Matrix
x <- c(1:10)
x <- cbind(x, x)
breaks <- list(c(1, 2, 4, 8, 10), c(1, 5, 10))
y <- cont2cat(x, breaks)
y
# Data frame
x <- c(1:10)
x <- data.frame(cbind(x, x))
breaks <- list(c(1, 2, 4, 8, 10), c(1, 5, 10))
y <- cont2cat(x, breaks)
y
# Vector
x <- c(1:10)
breaks <- c(1, 2, 4, 8, 10)
y <- cont2cat(x, breaks)
y

Run the code above in your browser using DataLab