recode {mStats} | R Documentation |
Recode a variable
Description
recode()
changes the values of a variable.
Usage
recode(data, var, ...)
Arguments
data |
data.frame |
var |
variable name |
... |
specify in pattern: |
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
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)
[Package mStats version 3.4.0 Index]