Takes a numeric variable (could be of class numeric or integer) and returns a discretized version, in which each element has been replaced by a single integer between 1 and nlevels, inclusive.

discretize(x, ...)

# S3 method for numeric
discretize(x, nlevels, method = "equal", ...)

# S3 method for integer
discretize(x, nlevels, ...)

# S3 method for FitLandDF
discretize(x, nlevels, ...)

Arguments

x

either a vector (numeric or integer) or FitLandDF object

...

potential additional arguments, currently unnecessary

nlevels

positive integer indicating number of discrete categories

method

method by which to discretize; split into equal sections by default ("equal" value for parameter)

Value

discretized form of x

Examples


## discretize a numeric vector
vec <- 1:10
discretize(vec, nlevels = 5) # discretize into 5 categories
#>  [1] 1 1 2 2 3 3 4 4 5 5
discretize(vec, 2)           # discretize into 2 categories
#>  [1] 1 1 1 1 1 2 2 2 2 2

## discretize a fitness landscape
# create a 3x3x3 fitness landscape with values 1 through 27
fl_data <- array(1:27, dim = rep(3, 3))
my_fl <- fitscape::FitLandDF(fl_data)
discretize(my_fl, nlevels = 2) # discretize landscape into 2 categories
#> [1] "A fitness landscape with dimensions 3x3x3 and for which 27 values are known."
discretize(my_fl, 5)           # discretize landscape into 5 categories
#> [1] "A fitness landscape with dimensions 3x3x3 and for which 27 values are known."