I have a dataframe which is formatted very much like an example dataframe df1 given below. There are three columns: two categorical variables and a 'Count' column specifying the amount of objects with that specific combination.
I want to move this data frame towards the format shown in example dataframe df2. Instead of a 'Count' column, each object is simply given on a seperate line.
I have tried things with the dplyr and tidyr packages but I am not yet very well-versed in R. What would be a good way to perform the function I want?
set.seed(1)
x1 <- c("Pants", "Shoes", "Scarf")
x2 <- c("Ugly", "Beautiful")
x3 <- sample(1:10, size=6, replace=T)
df1 <- data.frame(Object=rep(x1, 2),
Quality=rep(x2, each=3),
Count=x3);
df1; sum(df1[,3])
df2 <- data.frame(Object=c(rep("Pants", 3), rep("Shoes", 4), rep("Scarf", 6),
rep("Pants", 10), rep("Shoes", 3), rep("Scarf", 9)),
Quality=c(rep("Ugly", 3), rep("Ugly", 4), rep("Ugly", 6),
rep("Beautiful", 10), rep("Beautiful", 3),
rep("Beautiful", 9))
)
head(df2); tail(df2)