Last active
October 25, 2019 16:03
-
-
Save jmcastagnetto/0f26bc691037c7931f0202863447c094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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]) |
Author
jmcastagnetto
commented
Oct 25, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment