cont2cat {pedometrics} | R Documentation |
Compute break points and marginal strata proportions, stratify and convert continuous data (numeric) into categorical data (factor or integer).
cont2cat(x, breaks, integer = FALSE) breakPoints(x, n, type = "area", prop = FALSE) stratify(x, n, type = "area", integer = FALSE)
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 |
n |
Integer value; the number of strata that should be created. |
type |
Character value; the type of strata, with options |
prop |
Logical value; should the marginal strata proportions be
returned? Defaults to |
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.
A vector, data frame, or matrix, depending on the class of x
.
Alessandro Samuel-Rosa alessandrosamuelrosa@gmail.com
## 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