I have this df
structure(list(uniqueID = c(1512211, 1512211, 1512211, 58211,
58211, 58211, 58211), food_item = c("sp2", "sp3", "sp4", "sp10",
"sp3", "sp4", "sp5"), points = c(10, 3, 20, 2, 3, 4, 3)), spec = structure(list(
cols = list(uniqueID = structure(list(), class = c("collector_double",
"collector")), food_item = structure(list(), class = c("collector_character",
"collector")), points = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ";"), class = "col_spec"), row.names = c(NA,
-7L), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))
I'm trying to transform into a table like this, where each point is distributed in rows and the "SPs" individually mark the points, without overlap between each SP.
I did this code but didn't work
an_anj <- an_anj %>%
filter(uniqueID == "1512211") %>%
pivot_wider(names_from = food_item,
values_from = points,
values_fill = 0) %>%
uncount(points)
Erro: Problem with mutate() column _weight.
i _weight = points.
x _weight must be a vector, not a function.
i The error occurred in group 1: uniqueID = "anjos1512211".
Run rlang::last_error() to see where the error occurred.
When I do
an_anj <- an_anj %>%
filter(uniqueID == "1512211") %>%
pivot_wider(names_from = food_item,
values_from = points,
values_fill = 0)
I don't get separate rows

