I have a dataframe df as follows (my real data there are many columns):
  df <- read.table(text = "date    hfgf    lmo
       2019-01-01        0.7         1.4
       2019-02-01        0.11        2.3
       2019-03-01       1.22        6.7
       2020-04-01        0.44        5.2
       2020-05-01        0.19        2.3
       2021-06-01        3.97        9.5
       ,
             header = TRUE, stringsAsFactors = FALSE)
I would like to replace the monthly values in the columns value 1 value 2 etc by the yearly mean.
Note that I can melt and use summarize function but I need to keep the columns as they are.
 
     
     
    