I have seen tons of answers but could not get it right. Basically I want to show duplciate on separate row while performing pivot wider
.I created a unique variable as well but the result was either nested row or separate row for each column.
df <- structure(list(identifier = c("e1", "e1", "e2", "e2", "e1", "e1",
"e1", "e1", "e2", "e2"), label = c("Monaco", "became", "the",
"first", "the", "the", "Monaco", "became", "the", "first"), id = c("CP1",
"CP1", "CP1", "CP1", "CP1", "CP1", "CP2", "CP2", "CP2", "CP2"
), value = c(0L, 0L, 1L, 0L, 10L, 1L, 1L, 0L, 1L, 0L)), class = "data.frame", row.names = c(NA,
-10L))
library(tidyverse)
#My try
df %>%
group_by(identifier,label) %>%
mutate(rn=row_number()) %>%
pivot_wider( names_from="id",
values_from="value")