This is an example of one student input in the original data the Question_ID is more scrambled:
|Question_ID| Value |
| ——– | ——– |
| Q1_5A | 5 |
| Q1B | 0 |
| Q1C | 0 |
| Q1D | 0 |
| Q1E | 0 |
This is an example of another student later in the data:
| Q1_5A | 1 |
| Q1B | 1 |
| Q1C | 1 |
| Q1D | 1 |
| Q1E | 1 |
I would like to use the pivot wide function to make it like this:
Q1_5A | Q1B | Q1C | Q1D | Q1D |
---|---|---|---|---|
5 | 0 | 0 | 0 | 0 |
1 | 1 | 1 | 1 | 1 |
This is my current code:
pivot_wider(
data,
names_from = Question_ID,
values_from = value,
)
It produces an out put like this:
Q1_5A | Q1B. | Q1C. | Q1D. | Q1D. |
---|---|---|---|---|
c(5, 1) | c(0, 1) | c(0, 1) | c(0, 1) | c(0, 1) |
How can I change my pivot wider function to be outputting data like this:
Q1_5A | Q1B | Q1C | Q1D | Q1D |
---|---|---|---|---|
5 | 0 | 0 | 0 | 0 |
1 | 1 | 1 | 1 | 1 |
Jared Bean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.