Вы можете попробовать это:
library(tidyverse)
library(lubridate)
#Data
total.orders.by.date <- structure(list(Day = structure(c(17931, 17931, 17932, 18303,
18304), class = "Date"), Sales = c(219.12, 60.84, 200.27, 157.17,
12.14)), row.names = c("1", "2", "3", "4", "5"), class = "data.frame")
#Code
total.orders.by.date %>% mutate(Month=month(Day,label = T),Year=year(Day)) %>%
group_by(Year,Month) %>% summarise(Sales=sum(Sales,na.rm=T))
Вывод:
# A tibble: 2 x 3
# Groups: Year [2]
Year Month Sales
<dbl> <ord> <dbl>
1 2019 Feb 480.
2 2020 Feb 169.