From 0f49352bff0968528f894725fabb8cdc6bcb2878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie=20Wawrzyniak?= Date: Mon, 9 Dec 2024 16:22:02 +0100 Subject: [PATCH 1/4] random data generation --- R/random-data-generation.R | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 R/random-data-generation.R diff --git a/R/random-data-generation.R b/R/random-data-generation.R new file mode 100644 index 0000000..866f2ab --- /dev/null +++ b/R/random-data-generation.R @@ -0,0 +1,57 @@ +install.packages("openxlsx",lib = "/home/noemie/R/création_dataframe") +library(openxlsx, lib.loc = "/home/noemie/R/création_dataframe") + +prenoms <- c("Hector","Mari","Amance","Peter","Nathalie","Agathe","Romain","Eve","Marc","Enzo") +noms <- c("Dupont","Nguyen","Martin","Garcia","Fouquier","Dubois","Jack","Boisu","Zaky","Mathy") +filiere <- c(rep("EMIR",30),rep("MICA",30),rep("CLASSIQUE",140)) + +#réponses possibles +reponse_classique <- c("EII","MA","INFO","ET","GPM","GMA","GCU") +reponse_emir <- c("EII","INFO","GPM","ET") +reponse_mica <- c("GCU","MA","GMA","INFO") + +choix_colonnes <- c( + paste0("Q02_Voeux->", reponse_classique), + paste0("Q03_VoeuxEMIR->", reponse_emir), + paste0("Q04_voeuxMICA->", reponse_mica) +) + +nb_etudiants <- 200 + +df <- data.frame( + prenom = sample(prenoms, nb_etudiants, replace = TRUE), + nom = sample(noms, nb_etudiants, replace = TRUE), + filiere = sample(filiere, nb_etudiants, replace = TRUE) +) + +generer_voeux <- function(filiere) { + result <- rep(NA, length(choix_colonnes)) + names(result) <- choix_colonnes + + if (filiere == "CLASSIQUE") { + classement <- sample(reponse_classique) + result[paste0("Q02_Voeux->", classement)] <- 1:7 + } else if (filiere == "EMIR") { + classement <- sample(reponse_emir) + result[paste0("Q03_VoeuxEMIR->", classement)] <- 1:4 + } else if (filiere == "MICA") { + classement <- sample(reponse_mica) + result[paste0("Q04_voeuxMICA->", classement)] <- 1:4 + } + return(result) +} + +# ajout des voeux +df_voeux <- t(apply(df, 1, function(row) { + generer_voeux(row["filiere"]) +})) +df_voeux <- as.data.frame(df_voeux) + + +# fusion +df_final <- cbind(df, df_voeux) + +# affichage +print(df_final) +View(df_final) +write.xlsx(df_final,"/home/noemie/R/création_dataframe/ecrire.xlsx") \ No newline at end of file From 0920eb480ee576c67a4d389d8b37b3961ae52715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie=20Wawrzyniak?= Date: Mon, 9 Dec 2024 16:43:14 +0100 Subject: [PATCH 2/4] random data generation 2 --- R/random-data-generation.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/random-data-generation.R b/R/random-data-generation.R index 866f2ab..6d53643 100644 --- a/R/random-data-generation.R +++ b/R/random-data-generation.R @@ -1,5 +1,5 @@ -install.packages("openxlsx",lib = "/home/noemie/R/création_dataframe") -library(openxlsx, lib.loc = "/home/noemie/R/création_dataframe") + +library(openxlsx) prenoms <- c("Hector","Mari","Amance","Peter","Nathalie","Agathe","Romain","Eve","Marc","Enzo") noms <- c("Dupont","Nguyen","Martin","Garcia","Fouquier","Dubois","Jack","Boisu","Zaky","Mathy") From b5189d9e0f3240104028e013aedf404db4d3b216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie=20Wawrzyniak?= Date: Mon, 9 Dec 2024 16:45:53 +0100 Subject: [PATCH 3/4] random data generation 3 --- R/random-data-generation.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/random-data-generation.R b/R/random-data-generation.R index 6d53643..26947ed 100644 --- a/R/random-data-generation.R +++ b/R/random-data-generation.R @@ -1,4 +1,3 @@ - library(openxlsx) prenoms <- c("Hector","Mari","Amance","Peter","Nathalie","Agathe","Romain","Eve","Marc","Enzo") @@ -54,4 +53,4 @@ df_final <- cbind(df, df_voeux) # affichage print(df_final) View(df_final) -write.xlsx(df_final,"/home/noemie/R/création_dataframe/ecrire.xlsx") \ No newline at end of file +write.xlsx(df_final,"resultatfinal.xlsx") \ No newline at end of file From 95199a297c3843555e79a56290152148c26488cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie=20Wawrzyniak?= Date: Mon, 9 Dec 2024 17:15:03 +0100 Subject: [PATCH 4/4] delete View, install.packages, and paths --- R/random-data-generation.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/random-data-generation.R b/R/random-data-generation.R index 26947ed..cefeab3 100644 --- a/R/random-data-generation.R +++ b/R/random-data-generation.R @@ -51,6 +51,4 @@ df_voeux <- as.data.frame(df_voeux) df_final <- cbind(df, df_voeux) # affichage -print(df_final) -View(df_final) write.xlsx(df_final,"resultatfinal.xlsx") \ No newline at end of file