cont2cat {pedometrics}R Documentation

Stratification and categorization of continuous data

Description

Compute break points and marginal strata proportions, stratify and convert continuous data (numeric) into categorical data (factor or integer).

Usage

cont2cat(x, breaks, integer = FALSE)

breakPoints(x, n, type = "area", prop = FALSE)

stratify(x, n, type = "area", integer = FALSE)

Arguments

x

Vector, data frame or matrix; the continuous data to be processed.

breaks

Vector or list; the lower and upper limits that should be used to break the continuous data into categories. See ‘Details’ for more information.

integer

Logical value; should the categorical data be returned as integers? Defaults to integer = FALSE.

n

Integer value; the number of strata that should be created.

type

Character value; the type of strata, with options "area", for equal-area, and "range", for equal-range strata. Defaults to type = "area".

prop

Logical value; should the marginal strata proportions be returned? Defaults to prop = FALSE.

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.

Value

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

Author(s)

Alessandro Samuel-Rosa alessandrosamuelrosa@gmail.com

See Also

cut2

Examples


## Compute the break points of marginal strata
x <- data.frame(x = round(rnorm(10), 1), y = round(rlnorm(10), 1))
x <- breakPoints(x = x, n = 4, type = "area", prop = TRUE)
x

## Convert continuous data into categorical data
# Matrix
x <- y <- c(1:10)
x <- cbind(x, y)
breaks <- list(c(1, 2, 4, 8, 10), c(1, 5, 10))
y <- cont2cat(x, breaks)
y
# Data frame
x <- y <- c(1:10)
x <- data.frame(x, y)
breaks <- list(c(1, 2, 4, 8, 10), c(1, 5, 10))
y <- cont2cat(x, breaks, integer = TRUE)
y
# Vector
x <- c(1:10)
breaks <- c(1, 2, 4, 8, 10)
y <- cont2cat(x, breaks, integer = TRUE)
y

## Stratification
x <- data.frame(x = round(rlnorm(10), 1), y = round(rnorm(10), 1))
x <- stratify(x = x, n = 4, type = "area", integer = TRUE)
x

[Package pedometrics version 0.6-6 Index]