Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- recode <- function(x, old, new) {
- u <- rep(NA, length(x))
- for (i in 1:length(old)) {
- if(is.na(old[i])) {
- u[is.na(x)] <- new[i]
- } else {
- u[x == old[i]] <- new[i]
- }
- }
- return(ifelse(x %in% old, u, x))
- }
- a <- sample(c("A", "B", "C", "D", NA), 20, replace = T)
- recode(a, old = c("A", NA), new = c("E", "F"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement