Mean over a column if values in other column identical

Hello!

I have a table with three columns. In column 1 there is the ID, in column 2 there is a value that is used for comparison (identical for identical IDs) and in column 3 there is a value which is derived from an algorithm and which can differ by row.
Now, I want to aggregate all rows with the same ID so that I get the following format:

ID Value_Comparison Mean_Value

How is it possible to derive the mean value for column 3 for identical values in column 1? It is also possible to ignore column 2 and join it later, that would not matter.

suppressPackageStartupMessages({
  library(dplyr)
})

mtcars %>% group_by(cyl) %>% summarize(Mean_disp = mean(disp))
#> `summarise()` ungrouping output (override with `.groups` argument)
#> # A tibble: 3 x 2
#>     cyl Mean_disp
#>   <dbl>     <dbl>
#> 1     4      105.
#> 2     6      183.
#> 3     8      353.

Created on 2021-01-01 by the reprex package (v0.3.0.9001)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.