Last active
February 22, 2016 13:20
-
-
Save tchakravarty/8e45d43d171c59404aba to your computer and use it in GitHub Desktop.
R: Convert Excel Column Name into Column Number
This file contains 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
#============================================================================== | |
# purpose: get the column number from the column name in Excel | |
# author: tirthankar chakravarty | |
# created: 22nd february 2016 | |
# revised: 22nd february 2016 | |
# comments: | |
# - based on this SO answer: http://stackoverflow.com/a/1004624/1414455 | |
#============================================================================== | |
excel_name_to_number = function(name) { | |
Reduce(function(cumulative, next_element) { | |
cumulative*26 + utf8ToInt(next_element) - utf8ToInt("A") + 1 | |
}, x = strsplit(name, "")[[1]], init = 0) | |
} | |
excel_name_to_number("AAR") # 720 | |
excel_name_to_number("AR") # 44 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment