## Example with codes=TRUE
(f <- factor(letters[c(1, 1, 2, 3, 4, 5, 7, 8, 9, 8, 8, 10)]))
map <- mapFactor(f)
int <- as.integer(f)
fNew <- factor(int)
levels(fNew) <- map
fNew
## Example with codes=FALSE
f1 <- factor(f[1:5])
f2 <- factor(f[5:length(f)])
map1 <- mapFactor(f1, codes=FALSE)
map2 <- mapFactor(f2, codes=FALSE)
map <- c(map1, map2)
levels(f1) <- map
levels(f2) <- map
as.integer(f1)
as.integer(f2)
## x <- unique(map)
## names(x) <- unlist(x)
Run the code above in your browser using DataLab