How can I go from
df<-data.frame(id=c("A", "B", "B"), res=c("one", "two", "three"))
df
to
df.output<-data.frame(id=c("A", "B"), res1=c("one", "two"), res2=c(NA, "three"))
df.output
with dplyr
?
I do not know a priori the number of duplicates in id
(in this example B
has 2 occurrences), so the number of resX
variables in the output data frame has to be generated on the fly.