-1

I have a question that I can't answer myself even after searching for a while and for this reason I am hoping for a hint.

My challenge is that I have a time series that provides various other collected values as elements. The timestamps are stored in a column. In the other columns are the other values. The values are provided on a daily basis. Since I want to compare the values with another time series whose values are provided on a monthly basis, I want to summarize the values of the first table to average monthly values. I don't care if the values are added back to the original table or if a new table is created.

Many thanks in advance.

Update:

Unfortunately, the data is company data, so I cannot publish it. But maybe an example will help:

Timestamp Department Value1 Value2
1970-01-01 09:00:00 Procurement 0.4 0.9
1970-01-01 09:00:00 R&D 0.2 0.2
1970-01-01 09:00:00 IT 0.6 NA
1970-01-02 09:00:00 Procurement 0.1 0.2
1970-01-02 09:00:00 R&D NA 0.3
1970-01-02 09:00:00 IT 0.9 0.5
... ... ... ...
Ummsen
  • 11
  • 2

1 Answers1

0

You can create a month variable, and then group by and summarise the values

df %>% 
  mutate(month = month(Timestamp)) %>% 
  group_by(month) %>% 
  summarise(
    across(.cols = c(Value1,Value2),.fns = ~mean(.,na.rm = T))
  )
Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32