I use LETTERS most of the time for my factors but today I tried to go beyond 26 characters:
LETTERS[1:32]
Expecting there to be an automatic recursive factorization AA, AB, AC... But was disappointed. Is this simply a limitation of LETTERS or is there a way to get what I'm looking for using another function?
Would 702 be enough?
LETTERS702 <- c(LETTERS, sapply(LETTERS, function(x) paste0(x, LETTERS)))
If not, how about 18,278?
MOAR_LETTERS <- function(n=2) { n <- as.integer(n[1L]) if(!is.finite(n) || n < 2) stop("'n' must be a length-1 integer >= 2") res <- vector("list", n) res[[1]] <- LETTERS for(i in 2:n) res[[i]] <- c(sapply(res[[i-1L]], function(y) paste0(y, LETTERS))) unlist(res) } ml <- MOAR_LETTERS(3) str(ml) # chr [1:18278] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With