I have a dataframe with 213 rows and 2 columns (Date and Probability). Thanks to a previous post I am able to reduce the number of rows by grouping the Date by quarters. The problem is that, now, the second column, Probability, is composed by numbers that I want to average accordingly.
Let's take an example.
Date <- c("2000-01-05", "2000-02-03", "2000-03-02", "2000-03-30", "2000-04-13", "2000-05-11", "2000-06-08", "2000-07-06", "2000-09-14", "2000-10-05", "2000-10-19", "2000-11-02", "2000-12-14")
Article <- c(0.5, 1, 0.3, 0.8, 0.7, 2, 3, 1.5, 1, 2, 0.6, 0.5, 0.5)
Date <- data.frame(Date)
Article <- data.frame(Article)
df <- cbind(Date, Article)
#Dataframe
Date Probability
1 2000-01-05 0.5
2 2000-02-03 1
3 2000-03-02 0.3
4 2000-03-30 0.8
5 2000-04-13 0.7
6 2000-05-11 2
7 2000-06-08 3
8 2000-07-06 1.5
9 2000-09-14 1
10 2000-10-05 2
11 2000-10-19 0.6
12 2000-11-02 0.5
13 2000-12-14 0.5
The final output I would like to obtain is the following:
Date Probability
1 2000 Q1 0.65
2 2000 Q2 1.9
3 2000 Q3 1.25
4 2000 Q4 0.9
Essentially, the rows have been grouped together by quarters and the numbers associated have been averaged accordingly.
I have no idea how to do it, unfortunately.
Can anyone help me out?
Thanks!