My data looks like this :
structure(
list(
ID = c(1, 2, 3, 4, 5, 6),
Compagny = c("x", "x", "x", "y", "y", "y"),
Variable = c("size", "lenght", "diameter", "size", "lenght", "diameter"),
Score = c(12, 15, 8, 20, 4, 7)
),
row.names = c(NA, -6L),
class = "data.frame"
)
ID | Compagny | Variable | Score |
---|---|---|---|
1 | x | size | 12 |
2 | x | lenght | 15 |
3 | x | diameter | 8 |
4 | y | size | 20 |
5 | y | lenght | 4 |
6 | y | diameter | 7 |
i want to pivot wider so that variables are columns :
ID | Compagny | size | lenght | diameter |
---|---|---|---|---|
1 | x | 12 | 15 | 8 |
2 | y | 20 | 4 | 7 |
I've Followed this tutorial because i had the same problem pivot_wider issue "Values in `values_from` are not uniquely identified; output will contain list-cols"
I Copy/paste this lines of codes found above :
d %>%
group_by(name) %>%
mutate(row = row_number()) %>%
tidyr::pivot_wider(names_from = name, values_from = val) %>%
select(-row)
That became
PivoTable <- LongTable %>%
group_by(score) %>%
mutate(row = row_number()) %>%
tidyr::pivot_wider(names_from = score, values_from = mean) %>%
select(-row)
And I also have a special identifier for each row. It still doesn't work even though I dont have a propre table, but a matrix with NA values instead (cf. picture)