Skip to content

Instantly share code, notes, and snippets.

@druedin
Created February 1, 2014 20:23
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 druedin/8758265 to your computer and use it in GitHub Desktop.
Save druedin/8758265 to your computer and use it in GitHub Desktop.
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.
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