I am trying to combine some dirty data.
I have one data frame:
df <- data.frame(name = c("A", "A", "B", "B", "C", "C"), number = c(1, 1, 2, 2, 3, 3), product = c("fixed", "variable", "aggregate", "variable", "fixed", "fixed"), vol = c(1, 9, 2, 6, 4, 7) )
That's what I'm doing:
result <- data.frame(name = c("A", "B", "C"), number = c(1, 2, 3), new_product = c("fixed variable", "aggregate variable", "fixed"), vol = c(10, 8, 11) )
My problem: I need to combine all equal rows in a data frame. And if they are not unique, I need to combine them into a name similar to one of the results.
I tried dplyr, but in dplyr I cannot get new_product to merge in any meaningful way, because I cannot refer to the same column again.
df %>% group_by(name) %>% summarize (name = name, number = number, newproduct = paste(product, product)
Any help is much appreciated!