# Keith Matthews Exam Question…

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**Adventures in Data**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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

```
library(ggplot2)
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))
}
```

averages

```
mean(scores)
```

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

```
median(scores)
```

```
## [1] 1
```

plot

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

To

**leave a comment**for the author, please follow the link and comment on their blog:**Adventures in Data**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.