-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseq12.R
69 lines (55 loc) · 1.52 KB
/
seq12.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
chemin <- "https://minio.lab.sspcloud.fr/jpramil/formation_pemrdr"
chemin_enquete <- file.path(chemin, "enquete.RDS")
enquete <- rio::import(chemin_enquete)
a <- enquete %>%
mutate(
Sexe = factor(
Sexe,
levels = c("H", "F"),
labels = c("Homme", "Femme")
),
Actif = factor(
Actif,
levels = c(TRUE, FALSE),
labels = c("OUI", "NON")
)
) %>%
group_by(Actif, Sexe) %>%
summarise(n = n())
a %>%
spread(key = Sexe, value = n) %>%
mutate(total = sum(Homme,Femme,na.rm=TRUE)) %>%
mutate(part_femmes = round(Femme / total * 100, 1)) %>%
arrange(desc(part_femmes))
a %>%
pivot_wider(names_from = "Sexe", values_from = "n")
# Exercice --------------------------------------------------------------------
chemin_poplegale <- file.path(chemin, "poplegale_6815b.sas7bdat")
p <- rio::import(chemin_poplegale)
p %>%
pivot_longer(
cols = matches('PSDC|PMUN') ,
names_to = "millesime",
values_to = "pop"
) %>%
group_by(DC) %>%
filter(pop == max(pop)) %>%
mutate(annee = str_replace(millesime, 'PMUN', '20'),
annee = str_replace(annee, 'PSDC', '19'),
annee = as.numeric(annee)
) %>%
dplyr::slice_sample(n=100) %>%
View()
# Exercice complémentaire --------------------------------------------------------
tab <- data.frame(
dim = c("x", "y"),
a = c(1, -1),
b = c(2, -2),
c = c(3, -3),
d = c(4, -4),
e = c(5, -5),
f = c(6, -6)
)
tab %>%
pivot_longer(cols = -dim, names_to = "k") %>%
pivot_wider(names_from = "dim")