Skip to content

Instantly share code, notes, and snippets.

@patperu
Last active January 11, 2023 15:26
Show Gist options
  • Save patperu/bcf8891fc667738755bc9e8c2d8ec46c to your computer and use it in GitHub Desktop.
Save patperu/bcf8891fc667738755bc9e8c2d8ec46c to your computer and use it in GitHub Desktop.
Räumliche Bevölkerungsbewegung nach Haushaltstypen, Leipzig
#
# Räumliche Bevölkerungsbewegung nach Haushaltstypen, Leipzig
# Open Data Leipzig
#

library(tidyverse)

url <- "https://opendata.leipzig.de/dataset/fe3bbe2d-6118-40bc-8817-9f8c03b2f168/resource/8fbd6507-02a5-4368-859a-1e3662ddc57b/download/umzuegeleipzig2012ff.csv"

umzuege <- vroom::vroom(url) 
#> Rows: 566684 Columns: 9
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (5): zw, ot, gebiet, ags, haushaltsid
#> dbl (4): haushaltstyp, personenzahl, kinderzahl, jahr
#> 
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

umzuege |>
  count(haushaltsid, sort = TRUE) |> 
  slice_head(n = 1) |> 
  print() |> 
  left_join(umzuege, by = "haushaltsid") |> 
  select(-haushaltsid) |> 
  knitr::kable()
#> # A tibble: 1 × 2
#>   haushaltsid                                                          n
#>   <chr>                                                            <int>
#> 1 c46a3406b43cb392d0a567eabc21a58a89057a3e1b641792147ce87220a4e287    27
n zw ot haushaltstyp personenzahl kinderzahl jahr gebiet ags
27 w 71 5 11 7 2020 002 02000000
27 w 71 5 10 6 2020 003 03154028
27 w 71 5 10 6 2020 003 03154028
27 w 71 5 10 6 2020 003 03154028
27 w 71 5 10 6 2020 003 03154028
27 w 71 5 10 6 2020 003 03154028
27 w 71 5 10 6 2020 003 03154028
27 w 71 5 10 6 2020 003 03154028
27 w 71 5 10 6 2020 003 03154028
27 w 71 5 10 6 2020 003 03154028
27 w 71 5 10 6 2020 003 03154028
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 10 2 1 2020 011 11005005
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 8 7 5 2020 012 12052000
27 z 71 10 2 1 2020 011 11005005

Created on 2022-10-10 with reprex v2.0.2

# Update 11.01.2023 
#    - HashID korrigiert
#    - Zuzüge 2019 ergänzt


library(tidyverse)

url <- "https://opendata.leipzig.de/dataset/fe3bbe2d-6118-40bc-8817-9f8c03b2f168/resource/8fbd6507-02a5-4368-859a-1e3662ddc57b/download/umzuegeleipzig2012ff.csv"

umzuege <- vroom::vroom(url)
#> Rows: 639738 Columns: 9
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (5): zw, ot, gebiet, ags, haushaltsid
#> dbl (4): haushaltstyp, personenzahl, kinderzahl, jahr
#> 
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

umzuege |> 
  count(jahr, zw) |> 
  arrange(jahr) |> 
  pivot_wider(names_from = zw, values_from = n)
#> # A tibble: 11 × 3
#>     jahr     w     z
#>    <dbl> <int> <int>
#>  1  2012 19389 31130
#>  2  2013 20322 31775
#>  3  2014 21544 34704
#>  4  2015 21822 38946
#>  5  2016 24852 37849
#>  6  2017 24832 35051
#>  7  2018 25866 33143
#>  8  2019 26732 33268
#>  9  2020 23959 29744
#> 10  2021 24903 30377
#> 11  2022 27687 41843

Created on 2023-01-11 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment