coerce_discrete: Recode discrete data

Description Usage Arguments Details Examples

View source: R/s3-generics.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
coerce_discrete(x)

## S3 method for class 'factor'
coerce_discrete(x)

## S3 method for class 'numeric'
coerce_discrete(x)

## S3 method for class 'integer'
coerce_discrete(x)

## S3 method for class 'character'
coerce_discrete(x)

## S3 method for class 'data.frame'
coerce_discrete(x)

## S3 method for class '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

1
2
3
4
5
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

sparsebnUtils documentation built on Jan. 27, 2021, 9:05 a.m.