## 1. Integers.
## must be very sure these are truly integers, or else fails
x <- seq.int(2L, 22L, by = 2L)
## Specify range, 4 to 12 inclusive
missings <- "c(4, 12)"
assignMissing(x, missings)
missings <- " < 7"
assignMissing(x, missings)
missings <- " > 11"
assignMissing(x, missings)
## 2. strings
x <- c("low", "low", "med", "high")
missings <- "c(\"low\", \"high\")"
assignMissing(x, missings)
missings <- c("med", "doesnot exist")
assignMissing(x, missings)
## 3. factors (same as strings inside assignMissing)
x <- factor(c("low", "low", "med", "high"), levels = c("low", "med", "high"))
missings <- c("low", "high")
assignMissing(x, missings)
missings <- c("med", "doesnot exist")
assignMissing(x, missings)
## ordered factor:
x <- ordered(c("low", "low", "med", "high"), levels = c("low", "med", "high"))
missings <- c("low", "high")
assignMissing(x, missings)
## 4. Real-valued variable
set.seed(234234)
x <- rnorm(10)
missings <- "< 0"
assignMissing(x, missings)
missings <- "> -0.2"
assignMissing(x, missings)
missings <- "c(0.1, 0.7)"
assignMissing(x, missings)
Run the code above in your browser using DataLab