I would like to go from this: | Date | Code| Value| |--------| ----|------| |2017-S1 | 168 | 20000| |2017-S1 | 168 | 25000| |2017-S2 | 168 | 22000| |2017-S1 | 169 | 20000| |2017-S2 | 169 | 26000|
To this: | Date | Code| Value| |--------| ----|------| |2017-S1 | 168 | 22500| |2017-S2 | 168 | 22000| |2017-S1 | 169 | 20000| |2017-S2 | 169 | 26000|
CodePudding user response:
You need to group_by the variables Code and Date and then summarise Value using the meanfunction:
library(dplyr)
df %>%
group_by(Date, Code) %>%
summarise(Value = mean(Value))
