0

Consider the following data:

df <- data.frame(id=c(1,2,3,4,5),
                 v1=c(2020,2020,2021,2021,2022),
                 v2=c(12,5,66,17,17))

I need the output of the form (just averaging v2 based on v1):

id  v1     v2   avg_by_yr
 1  2020   12    8.5
 2  2020    5    8.5
 3  2021   66    41.5
 4  2021   17    41.5
 5  2022   17     17

Thanks!

iGada
  • 599
  • 3
  • 9

0 Answers0