label: Convert numerical values to a factor using specified labels

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 a specified set of labels. 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

labels

a vector specifying the set of labels

Details

The input vector v is converted to a factor with the set of levels corresponding to the unique values appearing in v, assigned labels specified by the labels argument. If missing, the default as.factor(v) conversion is applied.

Value

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

Author(s)

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

See Also

label.all

Examples

1
2
3
4
5
6
label(c(1, 0, 0, 1), c("neg", "pos"))
label(rep(1:3, 3), c("first", "second", "third"))
label(rep(3:1, 3), c("third", "second", "first"))

data(weather, package="dmr.data")
label(weather$play, c(0, 1))

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