label.all: Convert a numeric vector to a factor using all specified...

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

View source: R/r-utility-label.R

Description

This function converts a numeric vector to a factor with specified sets of levels and labels, possibly including levels not occurring in the input vector (which also have the corresponding labels assigned). It is used in examples presented in the book Cichosz, P. (2015): Data Mining Algorithms: Explained Using R. See Appendix B or http://www.wiley.com/go/data_mining_algorithms for more details.

Usage

1

Arguments

v

an input vector

levels

a vector specifying the set factor levels

labels

a vector specifying the set of factor labels

Details

The input vector v is converted to a factor with the set of levels specified by the levels argument and the set of corresponding labels specified by the labels argument. All levels are assigned the corresponding labels, including those not occurring in v. Values from v which do not appear in levels are replaced by NA.

Value

If levels!=NULL then factor(v, levels=levels, labels=labels) and as.factor(v) otherwise.

Author(s)

Pawel Cichosz <p.cichosz@elka.pw.edu.pl>

See Also

label

Examples

1
2
3
4
5
6
label.all(rep(1, 4), levels=0:1)
label.all(rep(1, 4), levels=0:1, labels=c("neg", "pos"))

data(weather, package="dmr.data")
label.all(weather$play[weather$play=="yes"], levels=c("no", "yes"))
label.all(weather$play[weather$play=="yes"], levels=c("no", "yes"), labels=c(0, 1))

42n4/dmr.util documentation built on May 20, 2019, 2:02 p.m.