How could I spread gear values using cyl as a key column?
Code
mtcars %>%
select(cyl, gear)%>%
spread(cyl, gear)
Error
Error: Duplicate identifiers for rows (3, 8, 9, 18, 19, 20, 21, 26, 27, 28, 32), (1, 2, 4, 6, 10, 11, 30), (5, 7, 12, 13, 14, 15, 16, 17, 22, 23, 24, 25, 29, 31)
Desired output
cyl gear
4 4,4,4,4,4,4,5,5,4
6 4,4,3,4,4,5
8 3,3,3,3,3,3,3,3,5,5