Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to extend LETTERS past 26 characters e.g., AA, AB, AC...?

Tags:

r

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?

like image 677
timothy.s.lau Avatar asked Sep 16 '14 19:09

timothy.s.lau


1 Answers

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" ... 
like image 149
Joshua Ulrich Avatar answered Sep 18 '22 11:09

Joshua Ulrich