delevels: Reduce (delete) or replace levels from a factor variable...

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/preprocess.R

Description

Reduce (delete) or replace levels from a factor variable (useful for preprocessing datasets).

Usage

1
delevels(x, levels, label = NULL)

Arguments

x

factor with several levels

levels

vector with the levels that will be replaced

label

the new label used for all levels examples (if NULL then "_OTHER" is assumed).

Value

Returns a factor with less levels.

Author(s)

Paulo Cortez http://www3.dsi.uminho.pt/pcortez

References

See fit.

See Also

fit and imputation.

Examples

1
2
3
4
5
6
7
8
f=factor(c("A","A","B","B","C","D","E"))
print(table(f))
f1=delevels(f,"A","a")
print(table(f1))
f2=delevels(f,c("C","D","E"),"CDE")
print(table(f2))
f3=delevels(f,c("B","C","D","E"))
print(table(f3))

Example output

f
A B C D E 
2 2 1 1 1 
f1
a B C D E 
2 2 1 1 1 
f2
  A   B CDE 
  2   2   3 
f3
     A _OTHER 
     2      5 

rminer documentation built on Dec. 16, 2019, 5:41 p.m.