makeFactor: Change numeric variables factors.

View source: R/utils.R View source: R/discretize.R

makeFactorR Documentation

Change numeric variables factors.

Description

Change numeric variables that are specified in varnames to factors so that discretize won't partition.

Usage

    makeFactor(df, varnames)

Arguments

df

Input data frame.

varnames

Names of variables to be converted to factors.

Author(s)

Norm Matloff <matloff@cs.ucdavis.edu>, Vincent Yang <vinyang@ucdavis.edu>, and Harrison Nguyen <hhnguy@ucdavis.edu>

Examples

data(prgeng)
pe <- prgeng[,c(1,3,5,7:9)]
class(pe$educ)  # integer
pe <- makeFactor(pe,c('educ','occ','sex'))
class(pe$educ)  # factor
# nice to give levels names
levels(pe$sex) <- c('male','female')
head(pe$sex)

matloff/cdparcoord documentation built on Feb. 24, 2025, 12:55 p.m.