0

I would like to group my data by months and show the total values of each month.

This is the code I have

test2 <- test %>%
  mutate(date=as.Date(date,format="%Y-%m-%d")) %>%
  group_by(month = floor_date(date,"month"))%>%
  summarise(predicts=sum(predicts))

This is what I am getting

  predicts
1 74622000

Here is a sample of my data

        date    predicts
1    2012-01-02 17282.96
2    2012-01-03 17025.44
3    2012-01-04 16815.49
4    2012-01-05 16935.29
5    2012-01-06 18311.89
Emm
  • 2,367
  • 3
  • 24
  • 50

1 Answers1

0

It could be an issue where we load plyr along with dplyr causing the summarise to get masked. Specify dplyr::summarise, dplyr::mutate explicitly or redo in a fresh session with dplyr only loaded. Also, wrap with month to extract the month, if that is what we need to group

library(dplyr)
library(lubridate)
test %>%
   dplyr::mutate(date=as.Date(date,format="%Y-%m-%d")) %>%
   group_by(month = floor_date(date,"month")) %>%
   dplyr::summarise(predicts=sum(predicts))
akrun
  • 874,273
  • 37
  • 540
  • 662