# Map students to presentation slots

As a teacher, I not only teach but also assess the achievements of students. One example of a typical student assignments is a presentation. You know, powerpoint slides and stuff.

For that purpose, I often need to map students to one of several time slots. Here’s the R code I use for that purpose.

``library(tidyverse)``
``## ── Attaching packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──``
``````## ✔ ggplot2 3.0.0     ✔ purrr   0.2.5
## ✔ tibble  1.4.2     ✔ dplyr   0.7.6
## ✔ tidyr   0.8.1     ✔ stringr 1.3.1
## ✔ readr   1.1.1     ✔ forcats 0.3.0``````
``## Warning: package 'dplyr' was built under R version 3.5.1``
``````## ── Conflicts ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──

How many students are subscribed to the assignment?

``stud_count <- 20``

Let’s say there 20 students in the course.

Let’s assume, for each time slot, 10 students can be allocated (not more time for more student for one slot).

``````slots_count <- (stud_count / 10) %>% ceiling  # round to next integer
slots_count``````
``##  2``

That gives 2 time slots.

Now let’s map the students to the slots on a random base:

``````slot <- 1:max(slots_count)

set.seed(2018)
allocation <- replicate(n = 10,
sample(x = slot)) %>% as.vector``````

What we’ve done here is:

1. Take the first triplet of students and randomly assign them to the three slots (so that each of the three students has a unique slot, ie sampling without replacement)
2. Repeat that for the rest of the triplets

Let’s check whether the `allocation` has worked:

``table(allocation)``
``````## allocation
##  1  2
## 10 10``````

``````library(rio)