library(magrittr)
library(dplyr)
let <- letters[1:5]
LET <- LETTERS[1:5]
int <- 0L:4L
num <- as.numeric(int)
fac <- factor(let)
css <- classified(let)
# any of these can mimic any other
str(mimic(LET, let))
str(mimic(num, let))
str(mimic(let, num))
# factors get a guide and classifieds get a named codelist
str(mimic(fac, int))
str(mimic(css, int))
# int can 'pick up' the factor levels as guide names
str(mimic(int, css))
# if two variables mean essentially the same thing,
# mimic lets you save space
x <- data.frame(id = 1:2, ID = c('A','B'))
x
x %<>% mutate(id = mimic(id, ID)) %>% select(-ID)
x
# ID still available, in principle:
x %>% as_decorated %>% resolve
Run the code above in your browser using DataLab