Last active
August 29, 2015 14:20
-
-
Save TonyLadson/6b2e757ce002b8d822e3 to your computer and use it in GitHub Desktop.
Test if a string is a valid gauge 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
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