I want to use pivot_wider
to create a wide list for a single date.
There are 8 different groups for one variable but the other variable is a summation.
data is like:
df <- data.frame(
stringsAsFactors = FALSE,
date = c("09/01/2020","09/01/2020",
"09/01/2020","09/01/2020","09/01/2020","09/01/2020",
"09/01/2020","09/01/2020"),
x = letters[1:8],
y = c(34L, 34L, 74L, 50L, 64L, 19L, 25L, 21L),
z = c(42L, 210L, 284L, 145L, 125L, 77L, 70L, 70L)
)
when using pivot_wider it creates 7 rows instead of 8 as the first two observations of y are 34 as below
df %>%
pivot_wider(names_from = x, values_from = z, values_fill = 0)