Last active
February 19, 2024 19:01
-
-
Save danlewer/08554e1da9770b6509f3803561f3dc6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here's a function that allows you to specify the number of letters you want (eg. 5 would be A, B, C, D, and E), the length of the code (eg. 3 would be AAA, AAB, AAC, etc), the number of results you want (NA for all of them), and and separating character (eg. '-' would give A-A-A, A-A-B, A-A-C.) | |
letterCodes <- function(nletters, case = 'upper', lengthCode, nResults = NA, sep = '') { | |
f <- if (case == 'upper') LETTERS else letters | |
a <- expand.grid(rep(list(f[1:nletters]), lengthCode)) | |
a <- a[, ncol(a):1] | |
a <- do.call("paste", c(a, sep = sep)) | |
if (is.na(nResults)) a else a[1:min(nResults, length(a))] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment