I would like to use the pipe function and aggregate the Damage for each compound based on Rate.
My code is as follows
MyData1=data.frame(Compound = c("c1","c1","c2","c2", "c3"), Damage= c(7,7,8,9,10), Rate = c(8,8,8,8,8))
MyData1 %>% filter(Rate == 8.000) %>%
group_by(Compound) %>%
summarize(mean_damage = mean(Damage, na.rm = TRUE))
Unfortunately this returns a single value. I would like to have the average damage for each compound at a given rate. So the output would have 3 rows, one for each compound, and average damage for each row in a separate column.
Thank you in advance.