-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_tidyverse.R
45 lines (37 loc) · 1.3 KB
/
main_tidyverse.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
# Fichier individu localisé au canton-ville (filcv)
# https://www.insee.fr/fr/statistiques/fichier/5542859/RP2018_INDCVI_csv.zip
# install.packages("tidyverse")
library("tidyverse")
library("readr")
# sélection de variables
sel <- c("CANTVILLE", "REGION", "DEPT", "IPONDI",
"CATL", "RECH", "MOCO", "CS1", "DIPL",
"EMPL", "IMMI", "INATC", "SEXE", "NBPI",
"TACT", "AGER20", "NA5")
# lecture du fichier
# rp18 <- read_csv2(file = "~/Documents/data/FD_INDCVI_2018.csv",
# col_types = list(character=(c("REGION", "DEPT", "CATL", "AGER20",
# "CS1", "DIPL", "EMPL", "TACT", "NA5"))))
# transform tibble
rp18 <- as_tibble(rp18)
# hab par REGION + DEPT
rp18 %>%
filter(REGION == "93") %>%
group_by(DEPT) %>%
summarise(n = sum(IPONDI, na.rm = TRUE))
# hab ~ REGION + DEP + CS1 large
rp18 %>%
filter(REGION == "93") %>%
group_by(DEPT, CS1) %>%
summarise(n = sum(IPONDI, na.rm = TRUE)) %>%
pivot_wider(id_cols = DEPT,
names_from = CS1,
values_from = n)
# hab ~ REGION + DEP + AGER20 large
rp18 %>%
filter(REGION == "93") %>%
group_by(DEPT, AGER20) %>%
summarise(n = sum(IPONDI, na.rm = TRUE)) %>%
pivot_wider(id_cols = DEPT,
names_from = AGER20,
values_from = n)