I have a data frame and I have grouped my data based on one of the columns (class). I want to create a sumproduct of two other columns (a and b) for each one of the unique values in the column that I have grouped them against. I have the following code but it doesn't calculate it correctly.
pools <- pools %>%
arrange(class) %>%
group_by(class) %>%
mutate(crossprod(pools$a,pools$b),
sumproduct=sum(a*b))%>%
ungroup()