R pivot_wider to keep one id per row [duplicate]
问题 This question already has answers here : Transpose / reshape dataframe without “timevar” from long to wide format (8 answers) Closed 7 months ago . I have a dataset with IDs and Value where one ID could take multiple values. Currently, the same ID is repeated row-wise when it has multiple values, but I hope to keep one ID per row, adding more columns when necessary. Here's a reproducible example: df <- data.frame(id = c(1,1,1,2,3,3), val = c(10:15)) What I want is df2 <- data.frame(id = c(1:3