Skip to content

Instantly share code, notes, and snippets.

@mdlincoln
Created February 9, 2018 16:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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