library(tidyverse)
df = data.frame(id=c(123,123),Method=c("angular","angular"),Colour=c("red","blue"))
df
df %>% group_by(id) %>%
mutate(entry = 1:n()) %>%
ungroup() %>%
pivot_wider(
names_from = entry,
values_from = c(Method,Colour),
names_sep = ''
) -> df2
df2
I give credit to Matt for sharing this useful pattern:
1 Like