-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate fake data #7
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
library(openxlsx) | ||
|
||
prenoms <- c("Hector","Mari","Amance","Peter","Nathalie","Agathe","Romain","Eve","Marc","Enzo") | ||
Check warning on line 3 in R/random-data-generation.R GitHub Actions / checks
Check warning on line 3 in R/random-data-generation.R GitHub Actions / checks
Check warning on line 3 in R/random-data-generation.R GitHub Actions / checks
Check warning on line 3 in R/random-data-generation.R GitHub Actions / checks
Check warning on line 3 in R/random-data-generation.R GitHub Actions / checks
Check warning on line 3 in R/random-data-generation.R GitHub Actions / checks
Check warning on line 3 in R/random-data-generation.R GitHub Actions / checks
Check warning on line 3 in R/random-data-generation.R GitHub Actions / checks
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created functions should be documented using the roxigen2 standard. |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the code should be nested into a functions, except for your constants (such as |
||
generer_voeux(row["filiere"]) | ||
})) | ||
df_voeux <- as.data.frame(df_voeux) | ||
|
||
|
||
# fusion | ||
df_final <- cbind(df, df_voeux) | ||
|
||
# affichage | ||
write.xlsx(df_final,"resultatfinal.xlsx") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions names, variable names and comments should be written in english.