reclass: Reclassify the values of a vector.

Description Usage Arguments Value Author(s) Examples

Description

Reclassify given values of a vector by new values. Note that all values need not to be documented, only the ones that need to be modified.

Usage

1
reclass(x, from, to = NULL, factor = FALSE, ...)

Arguments

x

A character or numeric vector.

from

A vector describing the values to change from, or a matrix of reclassification with two columns (from, to).

to

A vector describing the values to change to, or nothing if from is a matrix.

factor

Logical, whether to return a factor (default is FALSE).

...

Additional arguments passed to factor.

Value

A vector with the same length as x.

Author(s)

Mathieu Basille basille@ufl.edu

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
(bla <- rep(1:5, 3))
reclass(bla, c(3, 4), c(7, 3))
reclass(bla, c(3, 4), c("a", "b"))

## Conversion as a factor
reclass(bla, c(3, 4), c("a", "b"), factor = TRUE)
(bli <- rep(letters[1:5], 3))
reclass(bli, c("b", "d"), c(1, 2))

## With a matrix of reclassification
(mat <- matrix(c("b", "d", 1, 2), ncol = 2))
reclass(bli, mat)

## Fast computation time on large vectors
blu <- rpois(1e6, 10)
system.time(reclass(blu, c(3, 4), c(7, 3)))

basille/basr documentation built on May 11, 2019, 8:32 p.m.