recode: Recode

Description Usage Arguments Author(s) Examples

View source: R/recode.R

Description

A simple function for recoding, which aims to replace nested ifelse statements. Typical use cases include; recoding numeric vectors into a factor, merging factor levels in an existing factor, and more.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
recode(x, ..., by = x, drop = TRUE, add = FALSE, factor = FALSE,
  arrange = FALSE)

recode_(x, dots, by = x, ...)

spread_10(x)

spread_100(x)

spread_age(x, small = FALSE)

spread_employees(x)

Arguments

x

The vector to be recoded.

...

Named arguments with the criteria for the recodes. In essence recode = criteria. . can also be used as a shorthand for the vector given in by.

by

The vector to recode values in x 'by'. Defaults to x.

drop

Drop factor levels after recode. Will only remove levels that have no remaining observations after being explicitly recoded away from.

add

Set to TRUE to add levels to an existing factor variable.

factor

Convert numeric or character vectors to factor after recoding. Named recodes will be used as levels.

arrange

Set to TRUE to alphabetically sort the factor levels.

dots

A named list with either values that can be used with %in% or a boolean values.

small

Set to TRUE if you want small (5 year) age groups.

Author(s)

Kristian D. Olsen

Examples

1
2
3
4
recode(1:10L, small = 1:6L, medium = 7:8L, large = 9:10L)
recode_(1:10L, list(small = 1:6L, medium = 7:8L, large = 9:10L))
spread_10(1:10L)
spread_100(c(50, 65, 90))

itsdalmo/reporttoolDT documentation built on May 18, 2019, 7:11 a.m.