thanks in advance for the help.
There are several questions using spread
(from long to wide) on duplicate rows with unite
such as this.
I think what makes my question unique is the need to output dummy variables.
I anticipate an input like so:
df <- data.frame(id = c(1,1,2,3,4), fruit = c("apple","pear","apple","orange","apple"))
And an output like so:
output <- data.frame(id=c(1,2,3,4), apple = c(1,1,0,1), pear = c(1,0,0,0), orange = c(0,0,1,0))
Any help would be greatly appreciated. Thanks.