Learn R Programming

sparsebnUtils (version 0.0.8)

coerce_discrete: Recode discrete data

Description

Recodes discrete data so that the levels correspond to 0...n-1, where n is the total number of levels in a discrete factor.

Usage

coerce_discrete(x)

# S3 method for factor coerce_discrete(x)

# S3 method for numeric coerce_discrete(x)

# S3 method for integer coerce_discrete(x)

# S3 method for character coerce_discrete(x)

# S3 method for data.frame coerce_discrete(x)

# S3 method for sparsebnData coerce_discrete(x)

Arguments

x

an R object to coerce.

Details

Assumes data is unordered. Ordered factors are not supported at this time.

Examples

Run this code
# NOT RUN {
x <- 1:5
coerce_discrete(x) # output: 0 1 2 3 4

x <- c("high", "normal", "high", "low")
coerce_discrete(x) # output: 0 2 0 1

# }

Run the code above in your browser using DataLab