Skip to content

Instantly share code, notes, and snippets.

@jmcastagnetto
Last active October 25, 2019 16:03
Show Gist options
  • Save jmcastagnetto/0f26bc691037c7931f0202863447c094 to your computer and use it in GitHub Desktop.
Save jmcastagnetto/0f26bc691037c7931f0202863447c094 to your computer and use it in GitHub Desktop.
# Ref: https://twitter.com/Amit_Levinson/status/1187754568014336002
set.seed(2019)
gen_grades <- function(n, avg, sd, min, max, nsmpl) {
smpl <- rnorm(nsmpl, avg, sd)
smpl <- smpl[smpl >= min & smpl <= max]
if (length(smpl) >= n) {
return(sample(smpl, n))
} else {
stop(simpleError("Not enough sample data. Increase 'nsmpl'"))
}
}
grdmat <- matrix(nrow = 100, ncol = 10)
for(i in 1:10) {
grdmat[,i] = floor(gen_grades(n = 100, avg = 70, sd = 10, min = 54, max = 100, nsmpl = 1000))
}
df <- as.data.frame(grdmat)
rownames(df) <- paste0("Student_",1:100)
colnames(df) <- paste0("Course_",LETTERS[1:10])
@jmcastagnetto
Copy link
Author

> head(df)
          Course_A Course_B Course_C Course_D Course_E Course_F
Student_1       75       57       78       73       75       71
Student_2       99       57       61       71       63       75
Student_3       79       81       63       65       85       67
Student_4       57       73       56       79       76       96
Student_5       61       87       66       78       70       74
Student_6       66       75       91       67       78       69
          Course_G Course_H Course_I Course_J
Student_1       76       60       85       84
Student_2       72       55       79       78
Student_3       62       92       55       59
Student_4       73       72       73       75
Student_5       88       73       73       68
Student_6       64       68       82       71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment