# NOT RUN {
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)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab