x <- 1:5
data.frame(x, rev_num=RevCode(x), rev_fac=RevCode(factor(x)))
s <- c(3,4,2,7,4,9,NA,10)
RevCode(factor(s, levels=1:10))
i <- c(1,0,0,0,1,1)
cbind(i, RevCode(i))
k <- as.logical(c(1,0,0,0,1,1))
cbind(k, RevCode(k))
x <- factor(sample(letters[1:5], 10, replace = TRUE))
RevCode(x)
# we want to set the level 5 to NA before reversing
RevCode(factor(NAIf(x, "e")))
Run the code above in your browser using DataLab