recode: Recode a variable

Description Usage Arguments Details Value Author(s) Examples

View source: R/mStats.R

Description

recode() changes the values of a variable.

Usage

1

Arguments

data

data.frame

var

variable name

...

specify in pattern: old value / new value.

Details

It changes the values of a variable according to the old values specified. Values that does not meet any of the conditions, they are left unchanged.

Using colon : to indicate a range of numeric numbers

A numeric vector can be indicated by using : in old value. The function automatically filters the values that meet the range and assigns a specified new value to these.

Value

a data.frame

Author(s)

Email: dr.myominnoo@gmail.com

Website: https://myominnoo.github.io/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
x <- recode(infert, case, 0/"No", 1/"Yes")
tab(x, case)

## Not run: 
## recode a factor
x <- recode(infert, education, "0-5yrs"/1, "6-11yrs"/2, "12+ yrs"/3)
tab(x, education)

## recode numeric vectors
x <- recode(infert, age, 21:28.9/1, 29:34.9/2, 35:44/3)
tab(x, age)

## recode NA
infert[4:20, "case"] <- NA
x <- recode(infert, case, NA/"Missing value")
tab(infert, case)

## End(Not run)

mStats documentation built on Nov. 23, 2020, 9:07 a.m.

Related to recode in mStats...