Created
November 26, 2018 14:06
-
-
Save patperu/3bb43d4da5f6a9f7aea092118797dc5d to your computer and use it in GitHub Desktop.
Pendlerverflechtungen in Brandenburg
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
library(dplyr) | |
library(purrr) | |
library(glue) | |
library(tidyr) | |
lk <- data.frame(stringsAsFactors=FALSE, | |
gemziffer = c(12051, 12052, 12053, 12054, 12060, 12061, 12062, 12063, | |
12064, 12065, 12066, 12067, 12068, 12069, 12070, 12071, | |
12072, 12073), | |
Gebietsname = c("Brandenburg a.d. Havel", "Cottbus", "Frankfurt (Oder)", | |
"Potsdam", "Barnim", "Dahme-Spreewald", "Elbe-Elster", | |
"Havelland", "Märkisch-Oderland", "Oberhavel", | |
"Oberspreewald-Lausitz", "Oder-Spree", "Ostprignitz-Ruppin", "Potsdam-Mittelmark", | |
"Prignitz", "Spree-Neiße", "Teltow-Fläming", "Uckermark") | |
) | |
get_pendler <- function(regionInd, type, year_month) { | |
x <- glue('https://statistik.arbeitsagentur.de/PendlerData?type={type}&year_month={year_month}®ionInd={regionInd}&view=renderPendler') | |
x1 <- jsonlite::fromJSON(x) | |
purrr::map_df(x1, dplyr::bind_rows) %>% | |
mutate(Gebiet = regionInd, | |
Year_Month = year_month, | |
Austauschgebiet = names(x1), | |
Typ = type) %>% | |
select(Gebiet, Year_Month, Austauschgebiet, Typ, anzahl, frauen, maenner) | |
} | |
f_ein <- map_df(c(12051, 12052, 12053, 12054, 12060:12073), get_pendler, type = "ein", year_month = "201706") | |
f_aus <- map_df(c(12051, 12052, 12053, 12054, 12060:12073), get_pendler, type = "aus", year_month = "201706") | |
fin <- bind_rows(f_ein, f_aus) | |
fin <- left_join(fin, lk, by = c("Gebiet" = "gemziffer")) %>% | |
unite(Herkunftsgebiet, Gebiet, Gebietsname, sep = "_", remove = FALSE) | |
w <- tibble(Austauschgebiet_ = unique(fin$Herkunftsgebiet)) %>% | |
mutate(regionInd = substr(Austauschgebiet_, 1, 5)) | |
fin <- left_join(fin, w, by=c("Austauschgebiet" = "regionInd")) %>% | |
mutate(Austauschgebiet_ = if_else(is.na(Austauschgebiet_), Austauschgebiet, Austauschgebiet_)) %>% | |
select(Herkunftsgebiet, Austauschgebiet_, Year_Month, Typ, anzahl, frauen, maenner) %>% | |
rename(Austauschgebiet = Austauschgebiet_) | |
writexl::write_xlsx(fin, path = "Pendlerverflechtungen_Brandenburg.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment