0

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.

  • 6
    use `dplyr::summarise` or do this on a fresh R session with only dplyr loaded (seems like a classic case of [masking](https://stackoverflow.com/questions/9337716/how-do-i-use-functions-in-one-r-package-masked-by-another-package)) – akrun Jul 01 '20 at 20:44
  • I cannot replicate the behavior your describe. When I copy your code into an R session i get a tibble with three rows each with a mean for the different levels of "compound" – MrFlick Jul 01 '20 at 20:45
  • 1
    Thank you akrun, it worked! – Expectation mean first moment Jul 01 '20 at 20:48

0 Answers0