Skip to content

Instantly share code, notes, and snippets.

Created February 1, 2014 20:23
What would you like to do?
Two simple helper functions to use in conjuction with the postcode to canton converters at 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)
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))
plzvalid <- function(PLZ) {
# check if a number is a valid postcode; v.1.1 (1 Feb 2013)
# 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