Problem - Data Wrangling:
I want to fine adjust the note of a Multiple-Choice-Questions exam with 5 items on each question - A, B, C, D, E. I want to use coefficients on each possible item. For this I need to do some data wrangling:
Input:
library(tibble)
(
df <- tribble(
~id, ~Q1, ~Q2, ~Q3,
#|----|------|------|------|
1, "CDE", "A", "AD",
2, "CDE", "AB", "AD",
3, "DE", "BC", "AD")
)
Expected output :
| id | Q1_A | Q1_B | Q1_C | Q1_D | Q1_E | Q2_A | Q2_B | Q2_C | Q2_D | Q2_E | Q3_A | Q3_B | Q3_C | Q3_D | Q3_E |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
| 2 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
| 3 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |