Learn R Programming

gtexture (version 1.0.0)

discretize: Discretize Numeric Variable Into Categories

Description

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.

Usage

discretize(x, ...)

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

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

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

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

Value

discretized form of x

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)

Examples

Run this code

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

## 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
discretize(my_fl, 5)           # discretize landscape into 5 categories

Run the code above in your browser using DataLab