Skip to content

Instantly share code, notes, and snippets.

@druedin

druedin/plzcanton.R

Last active Nov 20, 2020
Embed
What would you like to do?
Convert Swiss postcode (Postleitzahl, PLZ) to cantons. Essentially this is a database with information which postcodes are in which canton. For 16 postcodes, it is not possible to assign the canton unambiguously; I have assigned one of the cantons according to the largest municipality/hamlet involved -- usually ignoring hamlets. Source of underl…
plzcanton <- function(PLZ, format=1) {
# convert Swiss postcode to canton; v.0.4 (20 Nov 2020) didier.ruedin@unine.ch
# format 1 = numeric
# format 2 = string
# DATA: BFS canton numbers:
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")
# DATA: postcodes:
ZH <- c(8970, 8955, 8954, 8953, 8952, 8951, 8942, 8934, 8933, 8932, 8926, 8925, 8915, 8914, 8913, 8912, 8911, 8910, 8909, 8908, 8907, 8906, 8904, 8903, 8902, 8901, 8833, 8825, 8824, 8820, 8816, 8815, 8813, 8812, 8810, 8805, 8804, 8803, 8802, 8801, 8800, 8714, 8713, 8712, 8708, 8707, 8706, 8704, 8703, 8702, 8700, 8639, 8637, 8636, 8635, 8634, 8633, 8632, 8630, 8627, 8626, 8625, 8624, 8623, 8622, 8621, 8620, 8618, 8617, 8616, 8615, 8614, 8613, 8612, 8610, 8608, 8607, 8606, 8605, 8604, 8603, 8602, 8600, 8548, 8545, 8544, 8543, 8542, 8523, 8499, 8498, 8497, 8496, 8495, 8494, 8493, 8492, 8489, 8488, 8487, 8486, 8484, 8483, 8482, 8479, 8478, 8477, 8476, 8475, 8474, 8472, 8471, 8468, 8467, 8466, 8465, 8464, 8463, 8462, 8461, 8460, 8459, 8458, 8457, 8453, 8452, 8451, 8450, 8447, 8444, 8442, 8428, 8427, 8426, 8425, 8424, 8423, 8422, 8421, 8418, 8416, 8415, 8414, 8413, 8412, 8411, 8410, 8409, 8408, 8406, 8405, 8404, 8402, 8401, 8400, 8354, 8353, 8352, 8345, 8344, 8343, 8342, 8340, 8335, 8332, 8331, 8330, 8325, 8322, 8320, 8317, 8315, 8314, 8312, 8311, 8310, 8309, 8308, 8307, 8306, 8305, 8304, 8303, 8302, 8301, 8248, 8247, 8246, 8245, 8197, 8196, 8195, 8194, 8193, 8192, 8187, 8185, 8184, 8183, 8182, 8181, 8180, 8175, 8174, 8173, 8172, 8166, 8165, 8164, 8162, 8158, 8157, 8156, 8155, 8154, 8153, 8152, 8143, 8142, 8136, 8135, 8134, 8133, 8132, 8130, 8127, 8126, 8125, 8124, 8123, 8122, 8121, 8118, 8117, 8115, 8114, 8113, 8112, 8108, 8107, 8106, 8105, 8104, 8103, 8102, 8099, 8098, 8096, 8093, 8092, 8091, 8090, 8088, 8087, 8086, 8085, 8081, 8080, 8075, 8074, 8071, 8070, 8068, 8066, 8065, 8064, 8063, 8061, 8060, 8059, 8058, 8057, 8055, 8053, 8052, 8051, 8050, 8049, 8048, 8047, 8046, 8045, 8044, 8042, 8041, 8040, 8039, 8038, 8037, 8036, 8034, 8033, 8032, 8031, 8030, 8027, 8026, 8024, 8023, 8022, 8021, 8020, 8016, 8015, 8012, 8011, 8010, 8008, 8006, 8005, 8004, 8003, 8002, 8001, 8000)
BE <- c(6197, 6086, 6085, 6084, 6083, 4955, 4954, 4953, 4952, 4950, 4944, 4943, 4942, 4938, 4937, 4936, 4935, 4934, 4933, 4932, 4924, 4923, 4922, 4919, 4917, 4916, 4914, 4913, 4912, 4911, 4902, 4901, 4900, 4704, 4539, 4538, 4537, 4536, 3864, 3863, 3862, 3860, 3858, 3857, 3856, 3855, 3854, 3853, 3852, 3826, 3825, 3824, 3823, 3822, 3818, 3816, 3815, 3814, 3813, 3812, 3807, 3806, 3805, 3804, 3803, 3800, 3792, 3785, 3784, 3783, 3782, 3781, 3780, 3778, 3777, 3776, 3775, 3773, 3772, 3771, 3770, 3766, 3765, 3764, 3763, 3762, 3758, 3757, 3756, 3755, 3754, 3753, 3752, 3725, 3724, 3723, 3722, 3718, 3717, 3716, 3715, 3714, 3713, 3711, 3707, 3706, 3705, 3704, 3703, 3702, 3700, 3674, 3673, 3672, 3671, 3665, 3664, 3663, 3662, 3661, 3658, 3657, 3656, 3655, 3654, 3653, 3652, 3647, 3646, 3645, 3638, 3636, 3635, 3634, 3633, 3632, 3631, 3629, 3628, 3627, 3626, 3625, 3624, 3623, 3622, 3619, 3618, 3617, 3616, 3615, 3614, 3613, 3612, 3609, 3608, 3607, 3605, 3604, 3603, 3602, 3601, 3600, 3557, 3556, 3555, 3553, 3552, 3551, 3550, 3543, 3538, 3537, 3536, 3535, 3534, 3533, 3532, 3531, 3513, 3512, 3510, 3508, 3507, 3506, 3504, 3503, 3476, 3475, 3474, 3473, 3472, 3465, 3464, 3463, 3462, 3457, 3456, 3455, 3454, 3453, 3452, 3439, 3438, 3437, 3436, 3435, 3434, 3433, 3432, 3429, 3428, 3427, 3426, 3425, 3424, 3423, 3422, 3421, 3419, 3418, 3417, 3416, 3415, 3414, 3413, 3412, 3402, 3401, 3400, 3380, 3377, 3376, 3375, 3374, 3373, 3372, 3368, 3367, 3366, 3365, 3363, 3362, 3360, 3326, 3325, 3324, 3323, 3322, 3321, 3317, 3315, 3314, 3313, 3312, 3309, 3308, 3306, 3305, 3303, 3302, 3298, 3297, 3296, 3295, 3294, 3293, 3292, 3283, 3282, 3274, 3273, 3272, 3271, 3270, 3268, 3267, 3266, 3264, 3263, 3262, 3257, 3256, 3255, 3252, 3251, 3250, 3238, 3237, 3236, 3235, 3234, 3233, 3232, 3226, 3225, 3208, 3207, 3205, 3204, 3203, 3202, 3183, 3179, 3177, 3176, 3174, 3173, 3172, 3159, 3158, 3157, 3156, 3155, 3154, 3153, 3152, 3150, 3148, 3147, 3145, 3144, 3132, 3128, 3127, 3126, 3125, 3124, 3123, 3122, 3116, 3115, 3114, 3113, 3112, 3111, 3110, 3099, 3098, 3097, 3096, 3095, 3089, 3088, 3087, 3086, 3085, 3084, 3083, 3082, 3078, 3077, 3076, 3075, 3074, 3073, 3072, 3071, 3070, 3068, 3067, 3066, 3065, 3063, 3054, 3053, 3052, 3050, 3049, 3048, 3047, 3046, 3045, 3044, 3043, 3042, 3041, 3040, 3039, 3038, 3037, 3036, 3035, 3034, 3033, 3032, 3030, 3029, 3027, 3024, 3020, 3019, 3018, 3017, 3015, 3014, 3013, 3012, 3011, 3010, 3008, 3007, 3006, 3005, 3004, 3003, 3002, 3001, 3000, 2762, 2748, 2747, 2746, 2745, 2744, 2743, 2742, 2740, 2738, 2736, 2735, 2733, 2732, 2723, 2722, 2720, 2717, 2716, 2715, 2713, 2712, 2710, 2616, 2615, 2613, 2612, 2610, 2608, 2607, 2606, 2605, 2604, 2603, 2577, 2576, 2575, 2572, 2565, 2564, 2563, 2562, 2560, 2558, 2557, 2556, 2555, 2554, 2553, 2552, 2543, 2542, 2538, 2537, 2536, 2535, 2534, 2533, 2532, 2520, 2518, 2517, 2516, 2515, 2514, 2513, 2512, 2510, 2505, 2504, 2503, 2502, 2501, 2500, 2333, 1797, 1738, 1657, 3206)
LU <- c(6404, 6356, 6354, 6353, 6344, 6295, 6294, 6289, 6288, 6287, 6286, 6285, 6284, 6283, 6281, 6280, 6277, 6276, 6275, 6274, 6265, 6264, 6263, 6262, 6260, 6253, 6252, 6248, 6247, 6246, 6245, 6244, 6243, 6242, 6236, 6235, 6234, 6233, 6232, 6231, 6222, 6221, 6218, 6217, 6216, 6215, 6214, 6213, 6212, 6211, 6210, 6208, 6207, 6206, 6205, 6204, 6203, 6196, 6192, 6182, 6174, 6173, 6170, 6167, 6166, 6163, 6162, 6161, 6160, 6156, 6154, 6153, 6152, 6147, 6146, 6145, 6144, 6143, 6142, 6133, 6132, 6130, 6126, 6125, 6123, 6122, 6114, 6113, 6112, 6110, 6106, 6105, 6103, 6102, 6048, 6047, 6045, 6044, 6043, 6039, 6038, 6037, 6036, 6035, 6034, 6033, 6032, 6031, 6030, 6028, 6027, 6026, 6025, 6024, 6023, 6022, 6021, 6020, 6019, 6018, 6017, 6016, 6015, 6014, 6013, 6012, 6011, 6009, 6008, 6007, 6006, 6005, 6004, 6003, 6002, 6000, 5735, 4915, 4806, 6010)
UR <- c(8751, 6493, 6491, 6490, 6487, 6485, 6484, 6482, 6476, 6475, 6474, 6473, 6472, 6469, 6468, 6467, 6466, 6465, 6464, 6463, 6462, 6461, 6460, 6454, 6441, 6377, 6452)
SZ <- c(8864, 8863, 8862, 8858, 8857, 8856, 8855, 8854, 8853, 8852, 8849, 8847, 8846, 8845, 8844, 8843, 8842, 8841, 8840, 8836, 8835, 8834, 8832, 8808, 8807, 8806, 6443, 6442, 6440, 6438, 6436, 6434, 6433, 6432, 6431, 6430, 6424, 6423, 6422, 6418, 6417, 6416, 6415, 6414, 6410, 6405, 6403, 6402)
OW <- c(6391, 6390, 6388, 6078, 6074, 6073, 6072, 6068, 6067, 6066, 6064, 6063, 6062, 6061, 6060, 6056, 6055, 6053)
NW <- c(6387, 6386, 6383, 6382, 6376, 6375, 6374, 6373, 6372, 6371, 6370, 6365, 6363, 6362, 6052)
GL <- c(8874, 8868, 8867, 8866, 8865, 8784, 8783, 8782, 8777, 8775, 8774, 8773, 8772, 8767, 8766, 8765, 8762, 8759, 8758, 8757, 8756, 8755, 8754, 8753, 8752, 8750)
ZG <- c(6349, 6346, 6345, 6343, 6342, 6341, 6340, 6333, 6332, 6331, 6330, 6319, 6318, 6317, 6315, 6314, 6313, 6312, 6310, 6304, 6303, 6302, 6301, 6300)
FR <- c(3286, 3285, 3284, 3280, 3216, 3215, 3214, 3213, 3212, 3210, 3186, 3185, 3184, 3182, 3178, 3175, 1796, 1795, 1794, 1793, 1792, 1791, 1789, 1788, 1786, 1785, 1784, 1783, 1782, 1776, 1775, 1774, 1773, 1772, 1763, 1762, 1757, 1756, 1754, 1753, 1752, 1749, 1748, 1747, 1746, 1745, 1744, 1742, 1741, 1740, 1737, 1736, 1735, 1734, 1733, 1732, 1731, 1730, 1728, 1727, 1726, 1725, 1724, 1723, 1722, 1721, 1720, 1719, 1718, 1717, 1716, 1715, 1714, 1713, 1712, 1709, 1708, 1707, 1705, 1704, 1702, 1701, 1700, 1699, 1697, 1696, 1695, 1694, 1692, 1691, 1690, 1689, 1688, 1687, 1686, 1685, 1684, 1681, 1680, 1679, 1678, 1677, 1676, 1675, 1674, 1673, 1670, 1669, 1667, 1666, 1665, 1663, 1661, 1656, 1654, 1653, 1652, 1651, 1649, 1648, 1647, 1646, 1645, 1644, 1643, 1642, 1638, 1637, 1636, 1635, 1634, 1633, 1632, 1631, 1630, 1628, 1627, 1626, 1625, 1624, 1623, 1619, 1618, 1617, 1616, 1615, 1614, 1611, 1609, 1583, 1568, 1567, 1566, 1564, 1563, 1553, 1544, 1542, 1541, 1533, 1532, 1529, 1528, 1527, 1489, 1486, 1485, 1484, 1483, 1482, 1475, 1474, 1473, 1470, 1468, 1565, 1787)
SO <- c(5746, 5015, 5014, 5013, 5012, 5010, 4719, 4718, 4717, 4716, 4715, 4714, 4713, 4712, 4710, 4703, 4702, 4658, 4657, 4656, 4655, 4654, 4653, 4652, 4640, 4634, 4633, 4632, 4630, 4629, 4628, 4626, 4625, 4624, 4623, 4622, 4621, 4620, 4618, 4617, 4616, 4615, 4614, 4613, 4612, 4611, 4609, 4603, 4601, 4600, 4588, 4587, 4586, 4585, 4584, 4583, 4582, 4581, 4579, 4578, 4577, 4576, 4574, 4573, 4571, 4566, 4565, 4563, 4562, 4558, 4557, 4556, 4554, 4553, 4552, 4551, 4543, 4542, 4535, 4534, 4533, 4532, 4528, 4525, 4524, 4523, 4522, 4515, 4514, 4513, 4512, 4509, 4503, 4502, 4501, 4500, 4468, 4421, 4413, 4412, 4252, 4247, 4245, 4234, 4233, 4232, 4229, 4228, 4227, 4226, 4208, 4206, 4204, 4146, 4145, 4143, 4118, 4116, 4115, 4114, 4112, 4108, 3307, 3254, 3253, 2545, 2544, 2540, 4564)
BS <- c(4125, 4096, 4095, 4094, 4093, 4092, 4091, 4089, 4088, 4087, 4086, 4085, 4084, 4083, 4082, 4081, 4080, 4078, 4075, 4070, 4065, 4059, 4058, 4057, 4056, 4055, 4054, 4053, 4052, 4051, 4041, 4039, 4035, 4034, 4033, 4032, 4031, 4030, 4025, 4024, 4020, 4019, 4018, 4017, 4016, 4015, 4013, 4012, 4011, 4010, 4009, 4008, 4007, 4005, 4004, 4003, 4002, 4001, 4000)
BL <- c(4497, 4496, 4495, 4494, 4493, 4492, 4469, 4467, 4466, 4465, 4464, 4463, 4462, 4461, 4460, 4458, 4457, 4456, 4455, 4453, 4452, 4451, 4450, 4448, 4447, 4446, 4445, 4444, 4443, 4442, 4441, 4438, 4437, 4436, 4435, 4434, 4433, 4432, 4431, 4426, 4425, 4424, 4423, 4422, 4419, 4418, 4417, 4416, 4415, 4414, 4411, 4410, 4402, 4304, 4302, 4254, 4253, 4246, 4244, 4243, 4242, 4225, 4224, 4223, 4222, 4207, 4203, 4202, 4153, 4148, 4147, 4144, 4142, 4133, 4132, 4127, 4124, 4123, 4117, 4107, 4106, 4105, 4104, 4103, 4102, 4101, 4042, 4040, 4023, 2814)
SH <- c(8455, 8454, 8263, 8262, 8261, 8260, 8243, 8242, 8241, 8240, 8239, 8236, 8235, 8234, 8233, 8232, 8231, 8228, 8226, 8225, 8224, 8223, 8222, 8219, 8218, 8217, 8216, 8215, 8214, 8213, 8210, 8208, 8207, 8205, 8204, 8203, 8202, 8201, 8200, 8212)
AR <- c(9035, 9037, 9038, 9042, 9043, 9044, 9052, 9053, 9055, 9056, 9062, 9063, 9064, 9100, 9101, 9102, 9103, 9104, 9105, 9107, 9112, 9405, 9410, 9411, 9414, 9426, 9427, 9428)
AI <- c(9413, 9108, 9058, 9057, 9054, 9050)
SG <- c(9303, 9658, 9657, 9656, 9655, 9652, 9651, 9650, 9643, 9642, 9633, 9631, 9630, 9622, 9621, 9620, 9615, 9614, 9613, 9612, 9608, 9607, 9606, 9604, 9602, 9601, 9552, 9536, 9534, 9533, 9527, 9526, 9525, 9524, 9523, 9512, 9510, 9501, 9500, 9479, 9478, 9477, 9476, 9475, 9473, 9472, 9471, 9470, 9469, 9468, 9467, 9466, 9465, 9464, 9463, 9462, 9453, 9452, 9451, 9450, 9445, 9444, 9443, 9442, 9437, 9436, 9435, 9434, 9430, 9425, 9424, 9423, 9422, 9404, 9403, 9402, 9401, 9400, 9327, 9323, 9313, 9312, 9308, 9305, 9304, 9301, 9300, 9249, 9248, 9247, 9246, 9245, 9244, 9243, 9242, 9240, 9231, 9230, 9212, 9205, 9204, 9203, 9201, 9200, 9127, 9126, 9125, 9123, 9122, 9116, 9115, 9114, 9113, 9036, 9034, 9033, 9032, 9030, 9029, 9028, 9027, 9026, 9025, 9024, 9023, 9022, 9020, 9016, 9015, 9014, 9013, 9012, 9011, 9010, 9009, 9008, 9007, 9006, 9004, 9001, 9000, 8898, 8897, 8896, 8895, 8894, 8893, 8892, 8890, 8889, 8888, 8887, 8886, 8885, 8884, 8883, 8882, 8881, 8880, 8879, 8878, 8877, 8873, 8872, 8740, 8739, 8738, 8737, 8735, 8734, 8733, 8732, 8730, 8727, 8726, 8725, 8723, 8722, 8718, 8717, 8716, 8715, 8646, 8645, 8638, 7326, 7325, 7324, 7323, 7320, 7317, 7315, 7314, 7313, 7312, 7310, 9442, 8640)
GR <- c(7748, 7747, 7746, 7745, 7744, 7743, 7742, 7741, 7710, 7610, 7608, 7606, 7605, 7604, 7603, 7602, 7563, 7562, 7560, 7559, 7558, 7557, 7556, 7554, 7553, 7552, 7551, 7550, 7546, 7545, 7543, 7542, 7537, 7536, 7535, 7534, 7533, 7532, 7530, 7527, 7526, 7525, 7524, 7523, 7522, 7517, 7516, 7515, 7514, 7513, 7512, 7505, 7504, 7503, 7502, 7500, 7494, 7493, 7492, 7484, 7482, 7477, 7473, 7472, 7464, 7463, 7462, 7460, 7459, 7458, 7457, 7456, 7455, 7454, 7453, 7452, 7451, 7450, 7448, 7447, 7446, 7445, 7444, 7443, 7442, 7440, 7438, 7437, 7436, 7435, 7434, 7433, 7432, 7431, 7430, 7428, 7427, 7426, 7425, 7424, 7423, 7422, 7421, 7419, 7418, 7417, 7416, 7415, 7414, 7413, 7412, 7411, 7408, 7407, 7405, 7404, 7403, 7402, 7307, 7306, 7304, 7303, 7302, 7278, 7277, 7276, 7272, 7270, 7265, 7260, 7252, 7250, 7249, 7247, 7246, 7245, 7244, 7243, 7242, 7241, 7240, 7235, 7233, 7232, 7231, 7228, 7226, 7224, 7223, 7222, 7220, 7215, 7214, 7213, 7212, 7208, 7206, 7205, 7204, 7203, 7202, 7201, 7189, 7188, 7187, 7186, 7185, 7184, 7183, 7182, 7180, 7176, 7175, 7174, 7173, 7172, 7168, 7167, 7166, 7165, 7164, 7163, 7162, 7159, 7158, 7157, 7156, 7155, 7154, 7153, 7152, 7151, 7149, 7148, 7147, 7146, 7145, 7144, 7143, 7142, 7141, 7138, 7137, 7136, 7135, 7134, 7133, 7132, 7130, 7128, 7127, 7126, 7122, 7116, 7115, 7114, 7113, 7112, 7111, 7110, 7109, 7107, 7106, 7104, 7084, 7083, 7082, 7078, 7077, 7076, 7075, 7074, 7064, 7063, 7062, 7058, 7057, 7056, 7050, 7032, 7031, 7029, 7028, 7027, 7026, 7023, 7019, 7018, 7017, 7016, 7015, 7014, 7013, 7012, 7007, 7006, 7004, 7003, 7002, 7001, 7000, 6565, 6563, 6562, 6558, 6557, 6556, 6549, 6548, 6547, 6546, 6545, 6544, 6543, 6542, 6541, 6540, 6538, 6537, 6535, 6534)
AG <- c(8967, 8966, 8965, 8964, 8962, 8957, 8956, 8919, 8918, 8917, 8916, 8905, 8109, 6042, 5745, 5742, 5737, 5736, 5734, 5733, 5732, 5728, 5727, 5726, 5725, 5724, 5723, 5722, 5712, 5708, 5707, 5706, 5705, 5704, 5703, 5702, 5647, 5646, 5645, 5644, 5643, 5642, 5637, 5636, 5634, 5632, 5630, 5628, 5627, 5626, 5625, 5624, 5623, 5622, 5621, 5620, 5619, 5618, 5617, 5616, 5615, 5614, 5613, 5612, 5611, 5610, 5608, 5607, 5606, 5605, 5604, 5603, 5601, 5600, 5525, 5524, 5522, 5512, 5507, 5506, 5505, 5504, 5503, 5502, 5467, 5466, 5465, 5464, 5463, 5462, 5454, 5453, 5452, 5445, 5444, 5443, 5442, 5436, 5432, 5431, 5430, 5426, 5425, 5423, 5420, 5417, 5416, 5415, 5413, 5412, 5408, 5406, 5405, 5404, 5402, 5401, 5400, 5334, 5333, 5332, 5330, 5326, 5325, 5324, 5323, 5322, 5318, 5317, 5316, 5315, 5314, 5313, 5312, 5306, 5305, 5304, 5303, 5301, 5300, 5277, 5276, 5275, 5274, 5273, 5272, 5246, 5245, 5244, 5243, 5242, 5237, 5236, 5235, 5234, 5233, 5232, 5225, 5224, 5223, 5222, 5213, 5212, 5210, 5201, 5200, 5116, 5113, 5112, 5108, 5107, 5106, 5105, 5103, 5102, 5085, 5084, 5083, 5082, 5080, 5079, 5078, 5077, 5076, 5075, 5074, 5073, 5072, 5070, 5064, 5063, 5062, 5058, 5057, 5056, 5054, 5053, 5046, 5044, 5043, 5042, 5040, 5037, 5036, 5035, 5034, 5033, 5032, 5028, 5027, 5026, 5025, 5024, 5023, 5022, 5018, 5017, 5004, 5001, 5000, 4856, 4853, 4852, 4814, 4813, 4812, 4809, 4808, 4807, 4805, 4803, 4802, 4801, 4800, 4665, 4663, 4334, 4333, 4332, 4325, 4324, 4323, 4322, 4317, 4316, 4315, 4314, 4313, 4312, 4310, 4305, 4303)
TG <- c(9573, 9565, 9562, 9556, 9555, 9554, 9553, 9548, 9547, 9546, 9545, 9543, 9542, 9535, 9532, 9517, 9515, 9514, 9508, 9507, 9506, 9504, 9503, 9502, 9326, 9325, 9322, 9320, 9315, 9314, 9306, 9225, 9223, 9220, 9217, 9216, 9215, 9214, 9213, 8599, 8598, 8597, 8596, 8595, 8594, 8593, 8592, 8590, 8589, 8588, 8587, 8586, 8585, 8584, 8583, 8582, 8581, 8580, 8577, 8576, 8575, 8574, 8573, 8572, 8570, 8566, 8565, 8564, 8561, 8560, 8558, 8556, 8555, 8554, 8553, 8552, 8547, 8546, 8540, 8537, 8536, 8535, 8532, 8530, 8526, 8525, 8524, 8522, 8520, 8514, 8512, 8510, 8508, 8507, 8506, 8505, 8503, 8502, 8501, 8500, 8376, 8374, 8372, 8371, 8370, 8363, 8362, 8360, 8357, 8356, 8355, 8285, 8280, 8274, 8273, 8272, 8269, 8268, 8267, 8266, 8265, 8264, 8259, 8255, 8254, 8253, 8252, 8546)
TI <- c(6999, 6998, 6997, 6996, 6995, 6994, 6993, 6992, 6991, 6990, 6989, 6988, 6987, 6986, 6984, 6983, 6982, 6981, 6980, 6979, 6978, 6977, 6976, 6974, 6968, 6967, 6966, 6965, 6964, 6963, 6962, 6959, 6958, 6957, 6956, 6955, 6954, 6953, 6952, 6951, 6950, 6949, 6948, 6947, 6946, 6945, 6944, 6943, 6942, 6939, 6938, 6937, 6936, 6935, 6934, 6933, 6932, 6930, 6929, 6928, 6927, 6926, 6925, 6924, 6922, 6921, 6919, 6918, 6917, 6916, 6915, 6914, 6913, 6912, 6910, 6908, 6907, 6906, 6905, 6904, 6903, 6902, 6901, 6900, 6883, 6877, 6875, 6874, 6873, 6872, 6867, 6866, 6865, 6864, 6863, 6862, 6855, 6854, 6853, 6852, 6850, 6839, 6838, 6837, 6836, 6835, 6834, 6833, 6832, 6830, 6828, 6827, 6826, 6825, 6823, 6822, 6821, 6818, 6817, 6816, 6815, 6814, 6810, 6809, 6808, 6807, 6806, 6805, 6804, 6803, 6802, 6781, 6780, 6777, 6776, 6775, 6774, 6773, 6772, 6764, 6763, 6760, 6749, 6748, 6747, 6746, 6745, 6744, 6743, 6742, 6724, 6723, 6722, 6721, 6720, 6719, 6718, 6717, 6716, 6715, 6714, 6713, 6710, 6707, 6705, 6703, 6702, 6696, 6695, 6694, 6693, 6692, 6690, 6685, 6684, 6683, 6682, 6678, 6677, 6676, 6675, 6674, 6673, 6672, 6670, 6664, 6663, 6662, 6661, 6659, 6658, 6657, 6656, 6655, 6654, 6653, 6652, 6648, 6647, 6646, 6645, 6644, 6637, 6636, 6635, 6634, 6633, 6632, 6631, 6622, 6618, 6616, 6614, 6613, 6612, 6611, 6605, 6604, 6602, 6601, 6600, 6599, 6598, 6597, 6596, 6595, 6594, 6593, 6592, 6590, 6584, 6583, 6582, 6579, 6578, 6577, 6576, 6575, 6574, 6573, 6572, 6571, 6533, 6532, 6528, 6527, 6526, 6525, 6524, 6523, 6518, 6517, 6516, 6515, 6514, 6513, 6512, 6511, 6506, 6503, 6501, 6500)
VD <- c(1892, 1885, 1884, 1882, 1880, 1867, 1866, 1865, 1864, 1863, 1862, 1860, 1856, 1854, 1853, 1852, 1847, 1846, 1845, 1844, 1833, 1832, 1824, 1823, 1822, 1820, 1818, 1817, 1816, 1815, 1814, 1811, 1809, 1808, 1807, 1806, 1805, 1804, 1803, 1802, 1801, 1800, 1683, 1682, 1660, 1659, 1658, 1613, 1612, 1610, 1607, 1589, 1588, 1587, 1586, 1585, 1584, 1582, 1580, 1562, 1555, 1554, 1552, 1551, 1545, 1543, 1538, 1537, 1536, 1535, 1530, 1526, 1525, 1524, 1523, 1522, 1521, 1515, 1514, 1513, 1512, 1510, 1509, 1464, 1463, 1462, 1454, 1453, 1452, 1450, 1446, 1445, 1443, 1442, 1441, 1440, 1439, 1438, 1437, 1436, 1435, 1434, 1433, 1432, 1431, 1430, 1429, 1428, 1427, 1426, 1425, 1424, 1423, 1422, 1421, 1420, 1418, 1417, 1416, 1415, 1413, 1412, 1409, 1408, 1407, 1406, 1405, 1404, 1401, 1400, 1377, 1376, 1375, 1374, 1373, 1372, 1358, 1357, 1356, 1355, 1354, 1353, 1352, 1350, 1348, 1347, 1346, 1345, 1344, 1343, 1342, 1341, 1338, 1337, 1330, 1329, 1326, 1325, 1324, 1323, 1322, 1321, 1320, 1318, 1317, 1316, 1315, 1313, 1312, 1311, 1310, 1308, 1307, 1306, 1305, 1304, 1303, 1302, 1300, 1299, 1297, 1296, 1295, 1291, 1279, 1278, 1277, 1276, 1275, 1274, 1273, 1272, 1271, 1270, 1269, 1268, 1267, 1266, 1265, 1264, 1263, 1262, 1261, 1260, 1197, 1196, 1195, 1189, 1188, 1187, 1186, 1185, 1184, 1183, 1182, 1180, 1176, 1175, 1174, 1173, 1172, 1170, 1169, 1168, 1167, 1166, 1165, 1164, 1163, 1162, 1149, 1148, 1147, 1146, 1145, 1144, 1143, 1142, 1141, 1136, 1135, 1134, 1132, 1131, 1128, 1127, 1126, 1125, 1124, 1123, 1122, 1121, 1117, 1116, 1115, 1114, 1113, 1112, 1110, 1098, 1097, 1096, 1095, 1094, 1093, 1092, 1091, 1090, 1088, 1085, 1084, 1083, 1082, 1081, 1080, 1078, 1077, 1076, 1073, 1072, 1071, 1070, 1068, 1066, 1063, 1062, 1061, 1059, 1058, 1055, 1054, 1053, 1052, 1047, 1046, 1045, 1044, 1043, 1042, 1041, 1040, 1039, 1038, 1037, 1036, 1035, 1034, 1033, 1032, 1031, 1030, 1029, 1028, 1027, 1026, 1025, 1024, 1023, 1022, 1020, 1019, 1018, 1017, 1015, 1014, 1012, 1011, 1010, 1009, 1008, 1007, 1006, 1005, 1004, 1003, 1002, 1001, 1000, 1410, 1534, 1595, 1608)
VS <- c(3999, 3998, 3997, 3996, 3995, 3994, 3993, 3992, 3991, 3989, 3988, 3987, 3986, 3985, 3984, 3983, 3982, 3979, 3978, 3977, 3976, 3975, 3974, 3973, 3972, 3971, 3970, 3968, 3967, 3966, 3965, 3963, 3961, 3960, 3957, 3956, 3955, 3954, 3953, 3952, 3951, 3949, 3948, 3947, 3946, 3945, 3944, 3943, 3942, 3940, 3939, 3938, 3937, 3935, 3934, 3933, 3932, 3931, 3930, 3929, 3928, 3927, 3926, 3925, 3924, 3923, 3922, 3920, 3919, 3918, 3917, 3916, 3914, 3913, 3912, 3911, 3910, 3908, 3907, 3906, 3905, 3904, 3903, 3902, 3901, 3900, 3801, 1997, 1996, 1994, 1993, 1992, 1991, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981, 1978, 1977, 1976, 1975, 1974, 1973, 1972, 1971, 1969, 1968, 1967, 1966, 1965, 1964, 1963, 1962, 1961, 1958, 1957, 1955, 1951, 1950, 1948, 1947, 1946, 1945, 1944, 1943, 1942, 1941, 1938, 1937, 1936, 1934, 1933, 1932, 1929, 1928, 1927, 1926, 1925, 1923, 1922, 1921, 1920, 1919, 1918, 1914, 1913, 1912, 1911, 1908, 1907, 1906, 1905, 1904, 1903, 1902, 1899, 1898, 1897, 1896, 1895, 1893, 1891, 1890, 1875, 1874, 1873, 1872, 1871, 1870, 1869, 1868)
NE <- c(2525, 2523, 2416, 2414, 2406, 2405, 2400, 2325, 2322, 2318, 2316, 2314, 2306, 2304, 2303, 2302, 2301, 2300, 2208, 2207, 2206, 2149, 2127, 2126, 2124, 2123, 2117, 2116, 2115, 2114, 2113, 2112, 2108, 2105, 2103, 2088, 2087, 2075, 2074, 2073, 2072, 2068, 2067, 2065, 2063, 2058, 2057, 2056, 2054, 2053, 2052, 2046, 2043, 2042, 2037, 2036, 2035, 2034, 2028, 2027, 2025, 2024, 2023, 2022, 2019, 2017, 2016, 2015, 2014, 2013, 2012, 2010, 2009, 2008, 2007, 2006, 2004, 2003, 2002, 2001, 2000)
GE <- c(1298, 1294, 1293, 1292, 1289, 1288, 1287, 1286, 1285, 1284, 1283, 1281, 1258, 1257, 1256, 1255, 1254, 1253, 1252, 1251, 1248, 1247, 1246, 1245, 1244, 1243, 1242, 1241, 1240, 1239, 1237, 1236, 1234, 1233, 1232, 1231, 1228, 1227, 1226, 1225, 1224, 1223, 1222, 1220, 1219, 1218, 1217, 1216, 1215, 1214, 1213, 1212, 1211, 1209, 1208, 1207, 1206, 1205, 1204, 1203, 1202, 1201, 1200, 1290)
JU <- c(2954, 2953, 2952, 2950, 2947, 2946, 2944, 2943, 2942, 2935, 2933, 2932, 2926, 2925, 2924, 2923, 2922, 2916, 2915, 2914, 2912, 2908, 2907, 2906, 2905, 2904, 2903, 2902, 2900, 2889, 2888, 2887, 2886, 2885, 2884, 2883, 2882, 2873, 2864, 2863, 2857, 2856, 2855, 2854, 2853, 2852, 2843, 2842, 2832, 2830, 2829, 2828, 2826, 2825, 2824, 2823, 2822, 2813, 2812, 2807, 2806, 2805, 2803, 2802, 2800, 2718, 2714, 2364, 2363, 2362, 2360, 2354, 2353, 2350, 2345, 2340, 2338, 2336, 2827)
# Liechtenstein & Germany:
FL <- c(9498, 9497, 9496, 9495, 9494, 9493, 9492, 9491, 9490, 9489, 9488, 9487, 9486, 9485)
DE <- c(8238)
# although not clearly assigned, here is how postcodes with two cantons were resolved.
# (basically: ignore the hamlets, taking only the larger municipalities)
# 8640 (Hurden SZ: N=271)
# 9442 (Briswilen AI, N=143)
# 8546 (Menzengrüt ZH, hamlet)
# 8212 (Nohl ZH, hamlet)
# 6452 (Riemenstalden SZ; N=92)
# 6010 (Pilatus Kulm OW: Hotel)
# 4564 (Zielebach BE, N=326)
# 3206 (Wallenbuch BE, N=132)
# 2827 (Schelten BE, N=39)
# 1787 (Mur VD, N=221 vs. 228 + 66)
# 1608 (Chapelle FR, N=258 vs. 559 others)
# 1595 (Clavaleyres BE, N=50)
# 1565 (Missy VD, N=325 vs. 351)
# 1534 (Chapelle (Broye) FR, N=64)
# 1410 (Prévondavaux FR, N=63)
# 1290 (Chavannes-des-Bois VD, N=750 vs. 13k)
# (1) convert PLZ to CANTON:
canton <- NA # nothing to start with
for(i in 1:26) { # 26 cantons
if (is.element(PLZ, get(clabels[i]))) canton <- i # get() to turn string into variable name
}
# (2) convert CANTON to STRING (if desired):
if (format==2){
canton <- clabels[canton] # assign labels
}
return(canton)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.