-2

enter image description here

Given is the snapshot of Spend DataFrame.

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
Ravi
  • 1
  • 2
  • 1
    Use `dput(YourDataFrame)` to paste a [Minimal, Complete, and Verifiable example of your data](https://stackoverflow.com/help/mcve) into the question itself – nghauran Sep 27 '18 at 15:11
  • 3
    `1.` R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization and general computing. **Provide minimal, reproducible, representative example(s) with your questions. Use dput() for data and specify all non-base packages with library calls. Do not embed pictures for data or code, use indented code blocks.** For statistics questions, use stats.stackexchange.com. `2.` calculating the average is not [data-science]. `3.` question has been answered here numerous times. – Andre Elrico Sep 27 '18 at 15:12
  • [This](https://stackoverflow.com/questions/16652199/compute-monthly-averages-from-daily-data) and also [this](https://stackoverflow.com/questions/23626299/calculate-average-monthly-total-by-groups-from-data-table-in-r) can help. Possible duplicates – nghauran Sep 27 '18 at 15:17

2 Answers2

3

using @Edgar's answer and enhacing it a little:

library(dplyr)
library(lubridate)

df %>%
  group_by(lubridate::month(Month),lubridate::year(Month) ) %>%
  summarise(month_average = mean(Amout))
Mouad_Seridi
  • 2,666
  • 15
  • 27
1

Given that your dataframe is named df:

library(dplyr)
library(lubridate)

df %>%
  group_by(lubridate::month(Month)) %>%
  summarise(month_average = mean(Amout))

Next time, try to provide a Minimum Reproducible Example

  • the problem here is that the `monthly average` would reflect the average of a particulat month of the year, not necessarly the same month. – Mouad_Seridi Sep 27 '18 at 15:19
  • 1
    If the question is about a particular month in a given year, just add `year(Month)` to the `group_by()` should do it. – Edgar Cutar Junior Sep 27 '18 at 15:21