Two simple helper functions to use in conjuction with the postcode to canton converters at https://gist.github.com/ruedin/6690720. The first converts cantonal ID to their abbreviated labels, the second checks if a number is a vald Swiss postcode.
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
convid <- function(ID) { | |
# function to convert cantonal ID, v.1.0 (12 Nov 2013) didier.ruedin@wolfson.oxon.org | |
clabels <- c("ZH", "BE", "LU", "UR", "SZ", "OW", "NW", "GL", "ZG", "FR", "SO", "BS","BL", "SH", "AR", "AI", "SG", "GR", "AG", "TG", "TI", "VD", "VS", "NE", "GE", "JU") | |
id <- ifelse(is.numeric(ID), clabels[ID], match(ID, clabels)) | |
return(id) | |
} | |
plzvalid <- function(PLZ) { | |
# check if a number is a valid postcode; v.1.1 (1 Feb 2013) didier.ruedin@wolfson.oxon.org | |
return(!is.na(plzcanton(PLZ))) | |
# usage: which(!sapply(1:1008, function(x) plzvalid(plz[x]))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment