I currently have the below data frame:
structure(list(cluster = c(2L, 3L, 5L, 5L, 6L, 6L, 7L, 9L, 9L,
10L, 10L), treatment = c("TreatmentA", "TreatmentA", "TreatmentA",
"TreatmentB", "TreatmentA", "TreatmentB", "TreatmentA", "TreatmentA",
"TreatmentB", "TreatmentA", "TreatmentB"), count = c(6, 6, 6,
6, 6, 6, 6, 2, 6, 1, 2)), row.names = c(NA, 11L), class = "data.frame")
I would like to add missing rows so that 'treatment' column has two rows for the numbers 1-10, each with a 'TreatmentA' and 'TreatmentB' value from the 'treatment' column. Additional rows would then have a value of 0 in the 'count' column.
Please see below the df I am trying to create:
structure(list(cluster = c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L,
5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L), treatment = c("TreatmentA",
"TreatmentB", "TreatmentA", "TreatmentB", "TreatmentA", "TreatmentB",
"TreatmentA", "TreatmentB", "TreatmentA", "TreatmentB", "TreatmentA",
"TreatmentB", "TreatmentA", "TreatmentB", "TreatmentA", "TreatmentB",
"TreatmentA", "TreatmentB", "TreatmentA", "TreatmentB"), count = c(0L,
0L, 6L, 0L, 6L, 0L, 0L, 0L, 6L, 6L, 6L, 6L, 6L, 0L, 0L, 0L, 2L,
6L, 1L, 2L)), class = "data.frame", row.names = c(NA, -20L))