Assigns a category to each element of a vector for a given set of threshold values.

categorize(x, categ, lower = FALSE)

Arguments

x

a numeric, complex, character or logical vector.

categ

a set of threshold values used to assign categories.

lower

a logical. If TRUE threshold values (i.e. values within categ) belongs to the lower category rather than the upper (default behavior).

Value

A vector of categories assigned.

Examples

categorize(stats::runif(40), categ=c(0.5,0.75))
#> [1] 1 2 2 1 3 2 1 2 2 2 1 1 1 2 1 1 2 3 1 1 2 1 2 2 1 3 3 3 3 1 1 1 1 2 1 3 1 2 #> [39] 1 1
categorize(LETTERS[1:5], categ='C')
#> [1] 1 1 2 2 2
categorize(LETTERS[1:5], categ='C', lower=TRUE)
#> [1] 1 1 1 2 2
categorize(LETTERS[floor(5*stats::runif(20))+1], categ=LETTERS[1:5], lower=TRUE)
#> [1] 5 2 3 2 3 1 5 3 3 2 3 2 1 3 2 1 2 3 5 2