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

前端 未结 9 1719
情书的邮戳
情书的邮戳 2020-12-03 00:52

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 automati

9条回答
  •  天命终不由人
    2020-12-03 01:51

    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" ...
    

提交回复
热议问题