Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How many columns does this spreadsheet have?
letter_position <- function(s) {
comp_str <- stringr::str_split(stringr::str_to_lower(s), "")
purrr::map_int(comp_str, alpha_index)
}
alpha_index <- function(s) {
i <- purrr::map_int(s, ~ which(. == letters))
purrr::reduce(i, function(x, y) {
x * length(letters) + y
})
}
#> letter_position(c("b", "ah", "qz"))
#> [1] 2 34 468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment