Skip to content

Instantly share code, notes, and snippets.

@TonyLadson
Last active August 29, 2015 14:20
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 TonyLadson/6b2e757ce002b8d822e3 to your computer and use it in GitHub Desktop.
Save TonyLadson/6b2e757ce002b8d822e3 to your computer and use it in GitHub Desktop.
Test if a string is a valid gauge number
isGaugeNum <- function(x) {
# returns true if value is missing, or a gauge number i.e. 6 digits followed by a capital letter
# otherwise returns false
if(!is.character(x)) return(FALSE)
if(is.na(x)) return(TRUE)
if(str_count(x) != 7) return(FALSE)
str_detect(x, "^[0-9]{6}[A-Z]{1}") # 6 digits followed by a capital letter
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment