I have a dataset that looks like the following.
df = data.frame(val=c(4,2,6,3,4,5),
algo=c("A","A","A","C","C","C"),
id=c("james","james","james",
"james","james","james"))
df
I want to alter the structure of the data frame so that it's in wide format.
id algo.A algo.C
james 4 3
james 2 4
james 6 5
I tried tidyr for this but get the following error.
> spread(df, id, algo)
Error: Duplicate identifiers for rows (1, 5)
Any suggestions on how to get the desired result?