Learn R Programming

CatEncoders (version 0.1.0)

LabelEncoder.fit: LabelEncoder.fit fits a LabelEncoder object

Description

LabelEncoder.fit fits a LabelEncoder object

Usage

LabelEncoder.fit(y)

Arguments

y
A vector of characters, factors, or numerics, which can include NA as well

Value

Returns an object of S4 class LabelEncoder.

Examples

Run this code
# factor y
y <- factor(c('a','d','e',NA),exclude=NULL)
lenc <- LabelEncoder.fit(y)
# new values are transformed to NA
z <- transform(lenc,factor(c('d','d',NA,'f')))
print(z)

# character y
y <- c('a','d','e',NA)
lenc <- LabelEncoder.fit(y)
# new values are transformed to NA
z <- transform(lenc,c('d','d',NA,'f'))
print(z)

# numeric y
set.seed(123)
y <- sample(c(1:10,NA),5)
lenc <- LabelEncoder.fit(y)
# new values are transformed to NA
z <-transform(lenc,sample(c(1:10,NA),5))
print(z)

Run the code above in your browser using DataLab