-
Notifications
You must be signed in to change notification settings - Fork 2
/
data handling_matrix_isere.R
75 lines (48 loc) · 2.11 KB
/
data handling_matrix_isere.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -------------------------------------------
# Isere - Mobilites professionnelles MOBPRO 2017 - 2020
#
# Download Data handling and matrix preparation
# -------------------------------------------
#rm(list=ls())
setwd("D:/R/github/transcarto/rflows/")
library("tidyverse")
#-----------------------
# I- download data
#-----------------------
data_url <- "https://www.insee.fr/fr/statistiques/fichier/4509353/base-csv-flux-mobilite-domicile-lieu-travail-2017.zip"
data_website <- "https://www.insee.fr/fr/statistiques/4509353"
data_source <- "INSEE, Mobilités professionnelles en 2017 : déplacements domicile - lieu de travail, Recensement de la population - Base flux de mobilité"
if(!dir.exists("./data/isere")){dir.create("data")}
if(!dir.exists("./data/isere/input")){dir.create("./data/isere/input")}
file <- "./data/isere/input/base-csv-flux-mobilite-domicile-lieu-travail-2017.zip"
# Dezip
#-----------------------
download.file(url =data_url, destfile = "./data/isere/input/mobpro2017.zip")
unzip("./data/isere/input/mobpro2017.zip", exdir = "data/isere/input")
file.remove("data/isere/input/mobpro2017.zip")
mobpro2017 <-st_read(dsn = "./data/isere/input/base-flux-mobilite-domicile-lieu-travail-2017.csv",
stringsAsFactors = F)
#-----------
# Extraction des OD de l'Isère (commune*commune)
#-----------
# Création d'un champs département origine et destination
#-----------
tabflow<-mobpro2017
tabflow=tabflow %>%
mutate (dept_O=CODGEO, dept_D=DCLT)
tabflow$dept_O <- substr(tabflow$dept_O, 1, 2)
tabflow$dept_D <- substr(tabflow$dept_D, 1, 2)
head(tabflow)
# Filtrage du département 38 en origine et zn destination
#-----------
tabflow=filter(tabflow,dept_O=="38")
tabflow=filter(tabflow,dept_D=="38")
head(tabflow)
# Variable typing
#-----------
tabflow$NBFLUX_C17_ACTOCC15P<-as.numeric(tabflow$NBFLUX_C17_ACTOCC15P)
# Export
#-----------
if(!dir.exists("./data/isere")){dir.create("data")}
if(!dir.exists("./data/isere/fij")){dir.create("./data/isere/fij")}
st_write(tabflow,"./data/isere/fij/mobpro_isere2017.csv")