### je charge la table K_individus
ik <- read_delim ("C:/Users/bmotteba/Nextcloud/Donnees/EMP_2019/Tables CSV/k_individu_public.csv" ,
delim = ";" , escape_double = FALSE , trim_ws = TRUE )
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 13825 Columns: 189
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr (4): NOIK, BABONNAUTOP, MDATE_jour, MDATE_mois
dbl (177): IDENT_MEN, IDENT_IND, pond_indC, TRAVAILLE, ETUDIE, BTRAVFIX, BTR...
lgl (8): BTYP4CART, BTYP4RES_A, BTYP4RES_B, BTYP4RES_C, BTYP4RES_D, BTYP4R...
ℹ 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.
itk <- read_delim ("C:/Users/bmotteba/Nextcloud/Donnees/EMP_2019/Tables CSV/tcm_ind_kish_public.csv" ,
delim = ";" , escape_double = FALSE , trim_ws = TRUE )
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 13825 Columns: 118
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr (18): NOI, AGEQ, AGQ, AGE6, AG6, LIEN_01, LIEN_02, LIEN_03, LIEN_04, LIE...
dbl (92): ident_ind, ident_men, ident_log, BS, HABRP, vague_enq, SEXE, ANAIS...
lgl (8): LIEN_08, LIEN_09, LIEN_10, AIDE1E, IDENTAID, JOUR2AN, MOISAND2, JO...
ℹ 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.
it <- read_delim ("C:/Users/bmotteba/Nextcloud/Donnees/EMP_2019/Tables CSV/tcm_ind_public.csv" ,
delim = ";" , escape_double = FALSE , trim_ws = TRUE )
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 31694 Columns: 16
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr (10): NOI, LIEN_01, LIEN_02, LIEN_03, LIEN_04, LIEN_05, LIEN_06, LIEN_07...
dbl (4): ident_ind, ident_men, ident_log, SEXE
lgl (2): LIEN_09, LIEN_10
ℹ 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.
mt <- read_delim ("C:/Users/bmotteba/Nextcloud/Donnees/EMP_2019/Tables CSV/tcm_men_public.csv" ,
delim = ";" , escape_double = FALSE , trim_ws = TRUE )
Rows: 13825 Columns: 84
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr (19): CS42PR, CS24PR, CODCSPR, CSCJDCD, CS42CJ, CS24CJ, CODCSCJ, CSMEN, ...
dbl (65): ident_men, ident_log, vague_enq, BS, pond_menC, NPERS, NCOUPLES, N...
ℹ 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.
##### chargement table déplacements
d <- read_delim ("C:/Users/bmotteba/Nextcloud/Donnees/EMP_2019/Tables CSV/k_deploc_public.csv" ,
delim = ";" , escape_double = FALSE , trim_ws = TRUE )
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 45169 Columns: 100
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr (23): MDATE_jour, MDATE_mois, NUTS_ORI, REG_ORI, oldREG_ORI, PAYS_ORI, ...
dbl (74): IDENT_DEP, IDENT_MEN, IDENT_IND, num_dep, nb_dep, POND_JOUR, mobl...
lgl (1): MTITR4S
time (2): MORIHDEP, MDESHARR
ℹ 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.
### fusion des 3 tables individus
i <- left_join (ik, itk, by = c ("IDENT_IND" = "ident_ind" ))
ii <- left_join (i, it, by = c ("IDENT_IND" = "ident_ind" ))
im <- left_join (ii, mt, by = c ("IDENT_MEN" = "ident_men" ))
## recodage variable distance
d <- d %>%
mutate (DIST = if_else (MDISTTOT_fin > 100 , 100 , MDISTTOT_fin)) %>% #transformation de la variable distances
mutate (DURE = if_else (DUREE > 120 , 120 , DUREE)) %>% #transformation de la variable duree
mutate (MOTIF = if_else ( #création d'une variable motif travail 0/1
(MMOTIFDES > 9 & MMOTIFDES < 10 ) |
(MMOTIFDES < 1.4 & (MOTPREC > 9 & MOTPREC < 10 )), 1 , 0 ))
d <- d %>% #emissions de CO2
mutate (CO2u = if_else (mtp > 2.3 , 0.0763 * DIST, 0 )) %>% #petite moto
mutate (CO2u = if_else (mtp > 2.5 , 0.191 * DIST, CO2u)) %>% #moto
mutate (CO2u = if_else (mtp > 3 , 0.216 * DIST, CO2u)) %>% #voiture
mutate (CO2u = if_else (mtp > 5 , 0.113 * DIST, CO2u)) %>% #bus gazole
mutate (CO2u = if_else (mtp > 5.5 , 8.91E-3 * DIST, CO2u)) %>% #ter
mutate (CO2u = if_else (mtp > 7 , 1 * DIST, CO2u)) #AVION
#### indicateurs de déplacements par individu
dd <- d %>%
group_by (IDENT_IND) %>% #on fait le max et la somme par individu
summarise (
som_dist = sum (DIST),
moy_dist = mean (DIST),
som_duree = sum (DURE),
moy_duree = mean (DURE),
som_dist_trav = sum (DIST[MOTIF == 1 ]),
moy_dist_trav = mean (DIST[MOTIF == 1 ]),
som_duree_trav = sum (DURE[MOTIF == 1 ]),
moy_duree_trav = mean (DURE[MOTIF == 1 ]),
som_dist_hors = sum (DIST[MOTIF == 0 ]),
moy_dist_hors = mean (DIST[MOTIF == 0 ]),
som_duree_hors = sum (DURE[MOTIF == 0 ]),
moy_duree_hors = mean (DURE[MOTIF == 0 ]),
som_CO2 = sum (CO2u),
moy_CO2 = mean (CO2u),
som_CO2_trav = sum (CO2u[MOTIF == 1 ]),
moy_CO2_trav = mean (CO2u[MOTIF == 1 ]),
som_CO2_hors = sum (CO2u[MOTIF == 0 ]),
moy_CO2_hors = mean (CO2u[MOTIF == 0 ]),
)
### fusion de la table avec la table individus
id <- left_join (im, dd, by = "IDENT_IND" )
### filtre
id <- id %>% filter (BTRAVTEL > 0 )
## Recodage de ik$BTRAVTEL en ik$teletrav_3M
id$ teletravail <- id$ BTRAVTEL %>%
as.character () %>%
fct_recode (
"1" = "2" ,
"1" = "3" ,
"1" = "4" ,
"0" = "5"
)
save (id, file = "C:/Users/bmotteba/Nextcloud/Donnees/EMP_2019/Tables CSV/id.RData" )
write_csv (id, file = "C:/Users/bmotteba/Nextcloud/Donnees/EMP_2019/Tables CSV/id.csv" )
######Cartes
####maps
library (sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
f <- st_read ("C:/Users/bmotteba/Downloads/regions-20180101.shp" )
Reading layer `regions-20180101' from data source
`C:\Users\bmotteba\Downloads\regions-20180101.shp' using driver `ESRI Shapefile'
Simple feature collection with 18 features and 5 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -61.80976 ymin: -21.38973 xmax: 55.83669 ymax: 51.08899
Geodetic CRS: WGS 84
ff <- f[f$ nuts2 %in% c ("FR10" ,"FR22" ,"FR61" ,"FR25" ,"FR51"
,"FR24" ,"FR21" ,"FR82" ,"FR52" ,"FR26" ,"FR62" ,"FR71" ), ]
plot (ff["code_insee" ])
## Recodage de id$NUTS_res en id$code_insee
id$ code_insee <- id$ NUTS_res %>%
fct_recode (
"11" = "FR10" ,
"24" = "FRB0" ,
"27" = "FRC1" ,
"27" = "FRC2" ,
"28" = "FRD1" ,
"28" = "FRD2" ,
"32" = "FRE1" ,
"32" = "FRE2" ,
"44" = "FRF1" ,
"44" = "FRF2" ,
"44" = "FRF3" ,
"52" = "FRG0" ,
"53" = "FRH0" ,
"75" = "FRI1" ,
"75" = "FRI2" ,
"75" = "FRI3" ,
"76" = "FRJ1" ,
"76" = "FRJ2" ,
"84" = "FRK1" ,
"84" = "FRK2" ,
"93" = "FRL0" ,
"94" = "FRM0"
)
reg <- id %>%
group_by (code_insee) %>% #on fait le max et la somme par individu
summarise (
reg_dist = mean (som_dist, na.rm = TRUE ),
reg_duree = mean (som_duree, na.rm = TRUE ),
reg_CO2 = mean (som_CO2, na.rm = TRUE )
)
reg_map <- merge (ff,reg, by= "code_insee" )