Description Usage Arguments Details Value Author(s) Examples
replace()
alters the contents of a variable when specified
conditions are met.
1 |
data |
data.frame |
var |
variable |
value |
value for replacement |
... |
|
If only value
is specified, the whole variable is assigned
with the value
. Multiple conditions can be specified within
the three dots.
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 19 20 21 22 | x <- replace(infert, case, 2, case == 0)
tab(x, case)
x <- replace(infert, parity, 4, parity > 4)
tab(x, parity)
## Not run:
## More examples
## replacing mpg with standardized values of mpg
replace(mtcars, mpg, mpg / mean(mpg))
## replacing mpg with NA if < 10 or > 20
replace(mtcars, mpg, NA, mpg < 10 | mpg > 20)
## replacing education levels with one value
replace(infert, education, "6+yrs",
education == "6-11yrs" | education == "12+ yrs")
## replacing mpg with NA if mpg is from 10 and 20.
replace(mtcars, mpg, NA, mpg >= 10, mpg <= 20)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.