Skip to content

Instantly share code, notes, and snippets.

@mdlincoln
Created February 9, 2018 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdlincoln/f6bcc37eeb330e4bfce002d71aa0aedd to your computer and use it in GitHub Desktop.
Save mdlincoln/f6bcc37eeb330e4bfce002d71aa0aedd to your computer and use it in GitHub Desktop.
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