Adding preprocessing
This commit is contained in:
parent
d3b4ded456
commit
37e9e6b129
1 changed files with 134 additions and 0 deletions
134
02_preprocessing.R
Normal file
134
02_preprocessing.R
Normal file
|
|
@ -0,0 +1,134 @@
|
||||||
|
library(dplyr)
|
||||||
|
library(tidyr)
|
||||||
|
library(ggplot2)
|
||||||
|
library(here)
|
||||||
|
|
||||||
|
full <- read.csv(file.path(
|
||||||
|
here(), "data",
|
||||||
|
"aggregated_dataframe_suppdiplome.csv"
|
||||||
|
))
|
||||||
|
|
||||||
|
full[["ine"]] <- as.factor(full[["ine"]])
|
||||||
|
# full[["cours"]] <- as.factor(full[["cours"]])
|
||||||
|
full[["ects"]] <- as.numeric(full[["ects"]])
|
||||||
|
full[["annee"]] <- as.factor(full[["annee"]])
|
||||||
|
full[["type_annee"]] <- as.factor(full[["type_annee"]])
|
||||||
|
full[["bloc"]] <- as.factor(full[["bloc"]])
|
||||||
|
# full[["parcours"]] <- as.factor(full[["parcours"]])
|
||||||
|
# full[["domaine2A"]] <- as.factor(full[["domaine2A"]])
|
||||||
|
# full[["dominante3A"]] <- as.factor(full[["dominante3A"]])
|
||||||
|
|
||||||
|
working_copy <- full
|
||||||
|
|
||||||
|
# Correction des typos
|
||||||
|
## Parcours
|
||||||
|
### Suppression des NAs
|
||||||
|
ine_missing_parcours <- unique(working_copy[is.na(working_copy[["parcours"]]), "ine"])
|
||||||
|
|
||||||
|
message(
|
||||||
|
"Il y a ",
|
||||||
|
length(ine_missing_parcours),
|
||||||
|
" étudiants qui n'ont pas de parcours renseignés et qui seront retirés."
|
||||||
|
)
|
||||||
|
|
||||||
|
missing_parcours <- which(working_copy[["ine"]] %in%
|
||||||
|
unique(working_copy[is.na(working_copy[["parcours"]]), "ine"]))
|
||||||
|
|
||||||
|
working_copy <- working_copy[-missing_parcours, ]
|
||||||
|
|
||||||
|
message(
|
||||||
|
"Après suppressions il reste ",
|
||||||
|
nrow(working_copy[is.na(working_copy[["parcours"]]), ]),
|
||||||
|
" étudiants qui n'ont pas de parcours renseignés"
|
||||||
|
)
|
||||||
|
|
||||||
|
### Renommage des parcours
|
||||||
|
working_copy[grep(
|
||||||
|
"Bio[-]?ingénierie moléculaire et cellulaire pour la santé",
|
||||||
|
working_copy[["parcours"]]
|
||||||
|
), "parcours"] <- "Bioingénierie moléculaire et cellulaire pour la santé"
|
||||||
|
|
||||||
|
working_copy[grep(
|
||||||
|
"([[:alpha:]])*Construction libre dans l'offre proposée par AgroParisTech",
|
||||||
|
working_copy[["parcours"]]
|
||||||
|
), "parcours"] <- "Construction libre dans l'offre proposée par AgroParisTech"
|
||||||
|
|
||||||
|
working_copy[grep(
|
||||||
|
"Bioraffineries - chimie verte",
|
||||||
|
working_copy[["parcours"]], fixed = TRUE
|
||||||
|
), "parcours"] <- "Bioraffinerie, chimie verte"
|
||||||
|
|
||||||
|
working_copy[grep(
|
||||||
|
"ingénierie des aliments",
|
||||||
|
working_copy[["parcours"]],
|
||||||
|
fixed = TRUE
|
||||||
|
), "parcours"] <- "Ingénierie des aliments"
|
||||||
|
|
||||||
|
working_copy[grep(
|
||||||
|
"Gestion des milieux naturels*",
|
||||||
|
working_copy[["parcours"]]
|
||||||
|
), "parcours"] <- "Gestion des milieux naturels ouverts et boisés"
|
||||||
|
|
||||||
|
working_copy[grep(
|
||||||
|
"*Santé, aliments et bioproduits",
|
||||||
|
working_copy[["parcours"]]
|
||||||
|
), "parcours"] <- "Santé, aliments et bioproduits"
|
||||||
|
|
||||||
|
working_copy[["parcours"]] <- as.factor(working_copy[["parcours"]])
|
||||||
|
|
||||||
|
## Domaine
|
||||||
|
if (length(unique(working_copy[["domaine2A"]])) == 6L) {
|
||||||
|
message("Les domaines sont déjà propres.")
|
||||||
|
} else {
|
||||||
|
stop("Il faut nettoyer les domaines !")
|
||||||
|
}
|
||||||
|
|
||||||
|
## Dominante
|
||||||
|
### Suppression des NAs
|
||||||
|
ine_missing_dominante <- unique(working_copy[is.na(working_copy[["dominante3A"]]), "ine"])
|
||||||
|
|
||||||
|
message(
|
||||||
|
"Il y a ",
|
||||||
|
length(ine_missing_dominante),
|
||||||
|
" étudiants qui n'ont pas de parcours renseignés et qui seront retirés."
|
||||||
|
)
|
||||||
|
|
||||||
|
missing_dominante <- which(working_copy[["ine"]] %in%
|
||||||
|
unique(working_copy[is.na(working_copy[["dominante3A"]]), "ine"]))
|
||||||
|
|
||||||
|
working_copy <- working_copy[-missing_dominante, ]
|
||||||
|
|
||||||
|
message(
|
||||||
|
"Après suppressions il reste ",
|
||||||
|
nrow(working_copy[is.na(working_copy[["dominante3A"]]), ]),
|
||||||
|
" étudiants qui n'ont pas de dominantes renseignées"
|
||||||
|
)
|
||||||
|
|
||||||
|
# grep(pattern = "M[1-2]{1}|Master", x = unique(working_copy[["dominante3A"]]),
|
||||||
|
# value = TRUE, invert = TRUE)
|
||||||
|
|
||||||
|
## Correction mauvais noms de cours
|
||||||
|
working_copy[grep(
|
||||||
|
"Initiation au métier de la recherche",
|
||||||
|
working_copy[["cours"]], fixed = TRUE
|
||||||
|
), "cours"] <- "Initiation aux métiers de la recherche"
|
||||||
|
|
||||||
|
working_copy[grep(
|
||||||
|
"Initiation au métier de la recherche",
|
||||||
|
working_copy[["cours"]], fixed = TRUE
|
||||||
|
), "cours"] <- "Initiation aux métiers de la recherche"
|
||||||
|
|
||||||
|
|
||||||
|
# Importation détails séquences
|
||||||
|
|
||||||
|
data_sequence <- read.csv(file.path(
|
||||||
|
here(), "data",
|
||||||
|
"details-sequence-nettoyes.csv"
|
||||||
|
))
|
||||||
|
|
||||||
|
joined_data <- full_join(working_copy, data_sequence, by = "cours")
|
||||||
|
|
||||||
|
|
||||||
|
non_matches <- unique(joined_data[is.na(joined_data[["code_cours"]]) & grepl("(MODULE INTEGRATIF|UE à choix*)", joined_data[["bloc"]]),][c("cours", "bloc")])
|
||||||
|
write.csv(non_matches, file =
|
||||||
|
file.path(here(), "data", "non-matche.csv"))
|
||||||
Loading…
Add table
Reference in a new issue