Description Usage Arguments Details Value Author(s) Examples
recode()
changes the values of a variable.
1 |
data |
data.frame |
var |
variable name |
... |
specify in pattern: |
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.
a data.frame
Email: dr.myominnoo@gmail.com
Website: https://myominnoo.github.io/
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.