Keith Matthews Exam Question…

December 14, 2016

(This article was first published on Adventures in Data, and kindly contributed to R-bloggers)

Help? I set an exam question with 10 boxes to be filled from 13 possible answers. If randomly completed, what should be the average mark?
– @KeithRMatthews, 12:13 PM – 15 Dec 2016

answers <- letters[1:10]
options <- letters[1:13]

functions to give random answers and mark them

giveAnswers <- function(options) sample(options, size = 10, replace = FALSE)
markAnswers <- function(correct, given) sum(given == correct)

collect scores

scores <- numeric(1e5L)
for(i in seq_along(scores)) {
  scores[i] <- markAnswers(answers, giveAnswers(options))


## [1] 0.766
## [1] 1


ggplot(data.frame(score = scores), aes(x = scores)) +
  geom_bar(stat = "count")

plot of chunk unnamed-chunk-5

To leave a comment for the author, please follow the link and comment on their blog: Adventures in Data. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)