I have the following dataframe, df
:
structure(list(x = structure(1:961, levels = c("2019-11-30",
"2019-12-01", "2019-12-02", "2019-12-03", "2019-12-04", "2019-12-05",
"2019-12-06", "2019-12-07", "2019-12-08", "2019-12-09", "2019-12-10",
"2019-12-11", "2019-12-12", "2019-12-13", "2019-12-14", "2019-12-15",
"2019-12-16", "2019-12-17", "2019-12-18", "2019-12-19", "2019-12-20",
"2019-12-21", "2019-12-22", "2019-12-23", "2019-12-24", "2019-12-25",
"2019-12-26", "2019-12-27", "2019-12-28", "2019-12-29", "2019-12-30",
"2019-12-31", "2020-01-01", "2020-01-02", "2020-01-03", "2020-01-04",
"2020-01-05", "2020-01-06", "2020-01-07", "2020-01-08", "2020-01-09",
"2020-01-10", "2020-01-11", "2020-01-12", "2020-01-13", "2020-01-14",
"2020-01-15", "2020-01-16", "2020-01-17", "2020-01-18", "2020-01-19",
"2020-01-20", "2020-01-21", "2020-01-22", "2020-01-23", "2020-01-24",
"2020-01-25", "2020-01-26", "2020-01-27", "2020-01-28", "2020-01-29",
"2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02", "2020-02-03",
"2020-02-04", "2020-02-05", "2020-02-06", "2020-02-07", "2020-02-08",
"2020-02-09", "2020-02-10", "2020-02-11", "2020-02-12", "2020-02-13",
"2020-02-14", "2020-02-15", "2020-02-16", "2020-02-17", "2020-02-18",
"2020-02-19", "2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23",
"2020-02-24", "2020-02-25", "2020-02-26", "2020-02-27", "2020-02-28",
"2020-02-29", "2020-03-01", "2020-03-02", "2020-03-03", "2020-03-04",
"2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08", "2020-03-09",
"2020-03-10", "2020-03-11", "2020-03-12", "2020-03-13", "2020-03-14",
"2020-03-15", "2020-03-16", "2020-03-17", "2020-03-18", "2020-03-19",
"2020-03-20", "2020-03-21", "2020-03-22", "2020-03-23", "2020-04-26",
"2020-04-27", "2020-04-28", "2020-04-29", "2020-04-30", "2020-05-01",
"2020-05-02", "2020-05-03", "2020-05-04", "2020-05-05", "2020-05-06",
"2020-05-07", "2020-05-08", "2020-05-09", "2020-05-10", "2020-05-11",
"2020-05-12", "2020-05-13", "2020-05-14", "2020-05-15", "2020-05-16",
"2020-05-17", "2020-05-18", "2020-05-19", "2020-05-20", "2020-05-21",
"2020-05-22", "2020-05-23", "2020-05-24", "2020-05-25", "2020-05-26",
"2020-05-27", "2020-05-28", "2020-05-29", "2020-05-30", "2020-05-31",
"2020-06-01", "2020-06-02", "2020-06-03", "2020-06-04", "2020-06-05",
"2020-06-06", "2020-06-07", "2020-06-08", "2020-06-09", "2020-06-10",
"2020-06-11", "2020-06-12", "2020-06-13", "2020-06-14", "2020-06-15",
"2020-06-16", "2020-06-17", "2020-06-18", "2020-06-19", "2020-06-20",
"2020-06-21", "2020-06-22", "2020-06-23", "2020-06-24", "2020-06-25",
"2020-06-26", "2020-06-27", "2020-06-28", "2020-06-29", "2020-06-30",
"2020-07-01", "2020-07-02", "2020-07-03", "2020-07-04", "2020-07-05",
"2020-07-06", "2020-07-07", "2020-07-08", "2020-07-09", "2020-07-10",
"2020-07-11", "2020-07-12", "2020-07-13", "2020-07-14", "2020-07-15",
"2020-07-16", "2020-07-17", "2020-07-18", "2020-07-19", "2020-07-20",
"2020-07-21", "2020-07-22", "2020-07-23", "2020-07-24", "2020-07-25",
"2020-07-26", "2020-07-27", "2020-07-28", "2020-07-29", "2020-07-30",
"2020-07-31", "2020-08-01", "2020-08-02", "2020-08-03", "2020-08-04",
"2020-08-05", "2020-08-06", "2020-08-07", "2020-08-08", "2020-08-09",
"2020-08-10", "2020-08-11", "2020-08-12", "2020-08-13", "2020-08-14",
"2020-08-15", "2020-08-16", "2020-08-17", "2020-08-18", "2020-08-19",
"2020-08-20", "2020-08-21", "2020-08-22", "2020-08-23", "2020-08-24",
"2020-08-25", "2020-08-26", "2020-08-27", "2020-08-28", "2020-08-29",
"2020-08-30", "2020-08-31", "2020-09-01", "2020-09-02", "2020-09-03",
"2020-09-04", "2020-09-05", "2020-09-06", "2020-09-07", "2020-09-08",
"2020-09-09", "2020-09-10", "2020-09-11", "2020-09-12", "2020-09-13",
"2020-09-14", "2020-09-15", "2020-09-16", "2020-09-17", "2020-09-18",
"2020-09-19", "2020-09-20", "2020-09-21", "2020-09-22", "2020-09-23",
"2020-09-24", "2020-09-25", "2020-09-26", "2020-09-27", "2020-09-28",
"2020-09-29", "2020-09-30", "2020-10-01", "2020-10-02", "2020-10-03",
"2020-10-04", "2020-10-05", "2020-10-06", "2020-10-07", "2020-10-08",
"2020-10-09", "2020-10-10", "2020-10-11", "2020-10-12", "2020-10-13",
"2020-10-14", "2020-10-15", "2020-10-16", "2020-10-17", "2020-10-18",
"2020-10-19", "2020-10-20", "2020-10-21", "2020-10-22", "2020-10-23",
"2020-10-24", "2020-10-25", "2020-10-26", "2020-10-27", "2020-10-28",
"2020-10-29", "2020-10-30", "2020-10-31", "2020-11-01", "2020-11-02",
"2020-11-03", "2020-11-04", "2020-11-05", "2020-11-06", "2020-11-07",
"2020-11-08", "2020-11-09", "2020-11-10", "2020-11-11", "2020-11-12",
"2020-11-13", "2020-11-14", "2020-11-15", "2020-11-16", "2020-11-17",
"2020-11-18", "2020-11-19", "2020-11-20", "2020-11-21", "2020-11-22",
"2020-11-23", "2020-11-24", "2020-11-25", "2020-11-26", "2020-11-27",
"2020-11-28", "2020-11-29", "2020-11-30", "2020-12-01", "2020-12-02",
"2020-12-03", "2020-12-04", "2020-12-05", "2020-12-06", "2020-12-07",
"2020-12-08", "2020-12-09", "2020-12-10", "2020-12-11", "2020-12-12",
"2020-12-13", "2020-12-14", "2020-12-15", "2020-12-16", "2020-12-17",
"2020-12-18", "2020-12-19", "2020-12-20", "2020-12-21", "2020-12-22",
"2020-12-23", "2020-12-24", "2020-12-25", "2020-12-26", "2020-12-27",
"2020-12-28", "2020-12-29", "2020-12-30", "2020-12-31", "2021-01-01",
"2021-01-02", "2021-01-03", "2021-01-04", "2021-01-05", "2021-01-06",
"2021-01-07", "2021-01-08", "2021-01-09", "2021-01-10", "2021-01-11",
"2021-01-12", "2021-01-13", "2021-01-14", "2021-01-15", "2021-01-16",
"2021-01-17", "2021-01-18", "2021-01-19", "2021-01-20", "2021-01-21",
"2021-01-22", "2021-01-23", "2021-01-24", "2021-01-25", "2021-01-26",
"2021-01-27", "2021-01-28", "2021-01-29", "2021-01-30", "2021-01-31",
"2021-02-01", "2021-02-02", "2021-02-03", "2021-02-04", "2021-02-05",
"2021-02-06", "2021-02-07", "2021-02-08", "2021-02-09", "2021-02-10",
"2021-02-11", "2021-02-12", "2021-02-13", "2021-02-14", "2021-02-15",
"2021-02-18", "2021-02-19", "2021-02-20", "2021-02-21", "2021-02-22",
"2021-02-23", "2021-02-24", "2021-02-25", "2021-02-26", "2021-02-27",
"2021-02-28", "2021-03-01", "2021-03-02", "2021-03-03", "2021-03-04",
"2021-03-05", "2021-03-06", "2021-03-07", "2021-03-08", "2021-03-09",
"2021-03-10", "2021-03-11", "2021-03-12", "2021-03-13", "2021-03-14",
"2021-03-15", "2021-03-16", "2021-03-17", "2021-03-18", "2021-03-19",
"2021-03-20", "2021-03-21", "2021-03-22", "2021-03-23", "2021-03-24",
"2021-03-25", "2021-03-26", "2021-03-27", "2021-03-28", "2021-03-29",
"2021-03-30", "2021-03-31", "2021-04-01", "2021-04-02", "2021-04-03",
"2021-04-04", "2021-04-05", "2021-04-06", "2021-04-07", "2021-04-08",
"2021-04-09", "2021-04-10", "2021-04-11", "2021-04-12", "2021-04-13",
"2021-04-14", "2021-04-15", "2021-04-16", "2021-04-17", "2021-04-18",
"2021-04-19", "2021-04-20", "2021-04-21", "2021-04-22", "2021-04-23",
"2021-04-24", "2021-04-25", "2021-04-26", "2021-04-27", "2021-04-28",
"2021-04-29", "2021-04-30", "2021-05-01", "2021-05-02", "2021-05-03",
"2021-05-04", "2021-05-05", "2021-05-06", "2021-05-07", "2021-05-08",
"2021-05-09", "2021-05-10", "2021-05-11", "2021-05-12", "2021-05-13",
"2021-05-14", "2021-05-15", "2021-05-16", "2021-05-17", "2021-05-18",
"2021-05-19", "2021-05-20", "2021-05-21", "2021-05-22", "2021-05-23",
"2021-05-24", "2021-05-25", "2021-05-26", "2021-05-27", "2021-05-28",
"2021-05-29", "2021-05-30", "2021-05-31", "2021-06-01", "2021-06-02",
"2021-06-03", "2021-06-04", "2021-06-05", "2021-06-06", "2021-06-07",
"2021-06-08", "2021-06-09", "2021-06-10", "2021-06-11", "2021-06-12",
"2021-06-13", "2021-06-14", "2021-06-15", "2021-06-16", "2021-06-17",
"2021-06-18", "2021-06-19", "2021-06-20", "2021-06-21", "2021-06-22",
"2021-06-23", "2021-06-24", "2021-06-25", "2021-06-26", "2021-06-27",
"2021-06-28", "2021-06-29", "2021-06-30", "2021-07-01", "2021-07-02",
"2021-07-03", "2021-07-04", "2021-07-05", "2021-07-06", "2021-07-07",
"2021-07-08", "2021-07-09", "2021-07-10", "2021-07-11", "2021-07-12",
"2021-07-13", "2021-07-14", "2021-07-15", "2021-07-16", "2021-07-17",
"2021-07-18", "2021-07-19", "2021-07-20", "2021-07-21", "2021-07-22",
"2021-07-23", "2021-07-24", "2021-07-25", "2021-07-26", "2021-07-27",
"2021-07-28", "2021-07-29", "2021-07-30", "2021-07-31", "2021-08-01",
"2021-08-02", "2021-08-03", "2021-08-04", "2021-08-05", "2021-08-06",
"2021-08-07", "2021-08-08", "2021-08-09", "2021-08-10", "2021-08-11",
"2021-08-12", "2021-08-13", "2021-08-14", "2021-08-15", "2021-08-16",
"2021-08-17", "2021-08-18", "2021-08-19", "2021-08-20", "2021-08-21",
"2021-08-22", "2021-08-23", "2021-08-24", "2021-08-25", "2021-08-26",
"2021-08-27", "2021-08-28", "2021-08-29", "2021-08-30", "2021-08-31",
"2021-09-01", "2021-09-02", "2021-09-03", "2021-09-04", "2021-09-05",
"2021-09-06", "2021-09-07", "2021-09-08", "2021-09-09", "2021-09-10",
"2021-09-11", "2021-09-12", "2021-09-13", "2021-09-14", "2021-09-15",
"2021-09-16", "2021-09-17", "2021-09-18", "2021-09-19", "2021-09-20",
"2021-09-21", "2021-09-22", "2021-09-23", "2021-09-24", "2021-09-25",
"2021-09-26", "2021-09-27", "2021-09-28", "2021-09-29", "2021-09-30",
"2021-10-01", "2021-10-02", "2021-10-03", "2021-10-04", "2021-10-05",
"2021-10-06", "2021-10-07", "2021-10-08", "2021-10-09", "2021-10-10",
"2021-10-11", "2021-10-12", "2021-10-13", "2021-10-14", "2021-10-15",
"2021-10-16", "2021-10-17", "2021-10-18", "2021-10-19", "2021-10-20",
"2021-10-21", "2021-10-22", "2021-10-23", "2021-10-24", "2021-10-25",
"2021-10-26", "2021-10-27", "2021-10-28", "2021-10-29", "2021-10-30",
"2021-10-31", "2021-11-01", "2021-11-02", "2021-11-03", "2021-11-04",
"2021-11-05", "2021-11-06", "2021-11-07", "2021-11-08", "2021-11-09",
"2021-11-10", "2021-11-11", "2021-11-12", "2021-11-13", "2021-11-14",
"2021-11-15", "2021-11-16", "2021-11-17", "2021-11-18", "2021-11-19",
"2021-11-20", "2021-11-21", "2021-11-22", "2021-11-23", "2021-11-24",
"2021-11-25", "2021-11-26", "2021-11-27", "2021-11-28", "2021-11-29",
"2021-11-30", "2021-12-01", "2021-12-02", "2021-12-03", "2021-12-04",
"2021-12-05", "2021-12-06", "2021-12-07", "2021-12-08", "2021-12-09",
"2021-12-10", "2021-12-11", "2021-12-12", "2021-12-13", "2021-12-14",
"2021-12-15", "2021-12-16", "2021-12-17", "2021-12-18", "2021-12-19",
"2021-12-20", "2021-12-21", "2021-12-22", "2021-12-23", "2021-12-24",
"2021-12-25", "2021-12-26", "2021-12-27", "2021-12-28", "2021-12-29",
"2021-12-30", "2021-12-31", "2022-01-01", "2022-01-02", "2022-01-03",
"2022-01-04", "2022-01-05", "2022-01-06", "2022-01-07", "2022-01-08",
"2022-01-09", "2022-01-10", "2022-01-11", "2022-01-12", "2022-01-13",
"2022-01-14", "2022-01-15", "2022-01-16", "2022-01-17", "2022-01-18",
"2022-01-19", "2022-01-20", "2022-01-21", "2022-01-22", "2022-01-23",
"2022-01-24", "2022-01-25", "2022-01-26", "2022-01-27", "2022-01-28",
"2022-01-29", "2022-01-30", "2022-01-31", "2022-02-01", "2022-02-02",
"2022-02-03", "2022-02-04", "2022-02-05", "2022-02-06", "2022-02-07",
"2022-02-08", "2022-02-09", "2022-02-10", "2022-02-11", "2022-02-12",
"2022-02-13", "2022-02-14", "2022-02-15", "2022-02-16", "2022-02-17",
"2022-02-18", "2022-02-19", "2022-02-20", "2022-02-21", "2022-02-22",
"2022-02-23", "2022-02-24", "2022-02-25", "2022-02-26", "2022-02-27",
"2022-02-28", "2022-03-01", "2022-03-02", "2022-03-03", "2022-03-04",
"2022-03-05", "2022-03-06", "2022-03-07", "2022-03-08", "2022-03-09",
"2022-03-10", "2022-03-11", "2022-03-12", "2022-03-13", "2022-03-14",
"2022-03-15", "2022-03-16", "2022-03-17", "2022-03-18", "2022-03-19",
"2022-03-20", "2022-03-21", "2022-03-22", "2022-03-23", "2022-03-24",
"2022-03-25", "2022-03-26", "2022-03-27", "2022-03-28", "2022-03-29",
"2022-03-30", "2022-03-31", "2022-04-01", "2022-04-02", "2022-04-03",
"2022-04-04", "2022-04-05", "2022-04-06", "2022-04-07", "2022-04-08",
"2022-04-09", "2022-04-10", "2022-04-11", "2022-04-12", "2022-04-13",
"2022-04-14", "2022-04-15", "2022-04-16", "2022-04-17", "2022-04-18",
"2022-04-19", "2022-04-20", "2022-04-21", "2022-04-22", "2022-04-23",
"2022-04-24", "2022-04-25", "2022-04-26", "2022-04-27", "2022-04-28",
"2022-04-29", "2022-04-30", "2022-05-01", "2022-05-02", "2022-05-03",
"2022-05-04", "2022-05-05", "2022-05-06", "2022-05-07", "2022-05-08",
"2022-05-09", "2022-05-10", "2022-05-11", "2022-05-12", "2022-05-13",
"2022-05-14", "2022-05-15", "2022-05-16", "2022-05-17", "2022-05-18",
"2022-05-19", "2022-05-20", "2022-05-21", "2022-05-22", "2022-05-23",
"2022-05-24", "2022-05-25", "2022-05-26", "2022-05-27", "2022-05-28",
"2022-05-29", "2022-05-30", "2022-05-31", "2022-06-01", "2022-06-02",
"2022-06-03", "2022-06-04", "2022-06-05", "2022-06-06", "2022-06-07",
"2022-06-08", "2022-06-09", "2022-06-10", "2022-06-11", "2022-06-12",
"2022-06-13", "2022-06-14", "2022-06-15", "2022-06-16", "2022-06-17",
"2022-06-18", "2022-06-19", "2022-06-20", "2022-06-21", "2022-06-22",
"2022-06-23", "2022-06-24", "2022-06-25", "2022-06-26", "2022-06-27",
"2022-06-28", "2022-07-02", "2022-07-03", "2022-07-04", "2022-07-05",
"2022-07-06", "2022-07-07", "2022-07-08", "2022-07-09", "2022-07-10",
"2022-07-11", "2022-07-12", "2022-07-13", "2022-07-14", "2022-07-15",
"2022-07-16", "2022-07-17", "2022-07-18", "2022-07-19", "2022-07-20",
"2022-07-21", "2022-07-22", "2022-07-23", "2022-07-24", "2022-07-25",
"2022-07-26", "2022-07-30", "2022-07-31", "2022-08-01", "2022-08-02",
"2022-08-03", "2022-08-04", "2022-08-05", "2022-08-06", "2022-08-07",
"2022-08-08", "2022-08-09", "2022-08-13", "2022-08-14", "2022-08-15",
"2022-08-16", "2022-08-17", "2022-08-18", "2022-08-19", "2022-08-20",
"2022-08-21", "2022-08-22", "2022-08-23", "2022-08-24", "2022-08-25",
"2022-08-26", "2022-08-27", "2022-08-28", "2022-08-29", "2022-08-30"
), class = "factor"), Freq = c(1733L, 4015L, 4303L, 4910L, 3522L,
5321L, 5027L, 3238L, 3505L, 6589L, 5685L, 4947L, 3060L, 2937L,
2903L, 2848L, 2608L, 2612L, 2749L, 3517L, 3665L, 3060L, 2569L,
18294L, 12148L, 2411L, 3449L, 1988L, 1829L, 2326L, 5475L, 5540L,
2990L, 7606L, 4555L, 2594L, 2844L, 3852L, 3836L, 3197L, 2879L,
3681L, 3852L, 3883L, 4277L, 3852L, 4769L, 6053L, 3411L, 4044L,
4556L, 3033L, 3404L, 3781L, 3154L, 2989L, 2514L, 1779L, 2431L,
3367L, 3809L, 4100L, 3231L, 2386L, 4859L, 3366L, 3162L, 3927L,
4927L, 4745L, 3976L, 6663L, 5079L, 4604L, 4038L, 3539L, 3863L,
3229L, 4094L, 3737L, 4130L, 3258L, 2793L, 3518L, 2484L, 3091L,
3254L, 5077L, 6138L, 4785L, 3941L, 3169L, 3172L, 3169L, 4099L,
4359L, 2936L, 2727L, 2469L, 2607L, 2796L, 2175L, 2380L, 2736L,
1911L, 2116L, 1334L, 1755L, 1540L, 1498L, 1624L, 1565L, 1053L,
1136L, 531L, 2051L, 4747L, 3713L, 3444L, 3366L, 2351L, 2990L,
2737L, 3341L, 3324L, 3352L, 3025L, 3034L, 2798L, 6294L, 3173L,
2381L, 3116L, 7693L, 3305L, 2020L, 1519L, 4155L, 4851L, 2881L,
3363L, 2842L, 2473L, 2500L, 2807L, 3427L, 3242L, 2834L, 2277L,
1518L, 1293L, 2077L, 2391L, 2784L, 2598L, 2439L, 1581L, 1615L,
2260L, 3139L, 3706L, 3420L, 2294L, 1758L, 2064L, 4765L, 3167L,
3078L, 2347L, 2251L, 1973L, 2261L, 2020L, 3583L, 2567L, 2692L,
3120L, 1974L, 1999L, 2232L, 2142L, 2146L, 3031L, 2278L, 2159L,
2358L, 3676L, 2663L, 2473L, 2744L, 2209L, 1887L, 1714L, 2542L,
2463L, 2779L, 3076L, 2087L, 1888L, 2012L, 1663L, 1983L, 3122L,
2244L, 2244L, 1536L, 1341L, 2339L, 3059L, 3169L, 11450L, 4797L,
5767L, 6397L, 3979L, 4319L, 3883L, 2412L, 2363L, 1680L, 1390L,
3319L, 3630L, 4479L, 3336L, 3244L, 2561L, 3390L, 4487L, 3841L,
4393L, 4166L, 3168L, 3855L, 4768L, 3310L, 4581L, 4952L, 10117L,
4505L, 2392L, 2261L, 3535L, 3599L, 3519L, 2993L, 3874L, 13878L,
8176L, 7789L, 7467L, 4444L, 3813L, 3056L, 2626L, 3661L, 5643L,
4664L, 4888L, 4062L, 5176L, 2296L, 4172L, 3070L, 4331L, 3255L,
3690L, 3322L, 3449L, 3250L, 3954L, 2836L, 3593L, 2818L, 2307L,
2838L, 1984L, 572L, 25604L, 9775L, 5367L, 9423L, 10249L, 4169L,
3180L, 3800L, 3127L, 3917L, 3074L, 1715L, 1801L, 2905L, 5582L,
2982L, 2722L, 26054L, 7396L, 4722L, 6250L, 4534L, 5098L, 6007L,
3814L, 6095L, 3363L, 3243L, 2238L, 2364L, 2713L, 1996L, 2117L,
2377L, 2702L, 2456L, 3402L, 4027L, 2558L, 2205L, 3918L, 3791L,
2547L, 3756L, 3394L, 2516L, 2234L, 3435L, 2629L, 3200L, 2507L,
2407L, 2121L, 1851L, 2027L, 2695L, 2456L, 2968L, 3008L, 3136L,
1829L, 1788L, 2739L, 2605L, 2201L, 2063L, 2537L, 2114L, 1881L,
3009L, 4067L, 3310L, 2800L, 2663L, 1910L, 1923L, 2643L, 3565L,
3926L, 2087L, 2349L, 1421L, 1574L, 2572L, 2873L, 2276L, 1901L,
1987L, 2599L, 1979L, 2177L, 2019L, 2043L, 1761L, 2028L, 1444L,
1998L, 2362L, 2953L, 4943L, 3398L, 2331L, 1960L, 2021L, 2902L,
4087L, 3352L, 4174L, 4906L, 3828L, 2470L, 3122L, 3536L, 6151L,
5048L, 3972L, 2600L, 2982L, 3599L, 3689L, 4302L, 4236L, 5424L,
3668L, 4087L, 5934L, 4555L, 3594L, 3293L, 2973L, 3036L, 4203L,
2895L, 12486L, 24477L, 14390L, 12224L, 8245L, 12426L, 5115L,
4420L, 3097L, 2421L, 3333L, 5281L, 4770L, 3341L, 3720L, 3767L,
3975L, 5051L, 3300L, 3637L, 3701L, 6690L, 3341L, 3342L, 2353L,
2763L, 4509L, 3178L, 3249L, 2681L, 2176L, 2093L, 3360L, 2871L,
3125L, 4315L, 4101L, 3824L, 2833L, 14263L, 8366L, 3938L, 8002L,
5380L, 2634L, 2158L, 4239L, 3055L, 3789L, 3065L, 2614L, 2472L,
2316L, 4014L, 3266L, 3684L, 2873L, 2148L, 1651L, 2150L, 3484L,
3975L, 3940L, 5409L, 4057L, 3457L, 3172L, 3145L, 3629L, 3583L,
5291L, 5038L, 3359L, 2343L, 3311L, 3863L, 5337L, 6546L, 3562L,
2423L, 3213L, 3019L, 7039L, 8057L, 4782L, 3539L, 3071L, 2750L,
3641L, 3663L, 4227L, 3050L, 2971L, 2905L, 2042L, 3176L, 7276L,
5240L, 3357L, 4890L, 3753L, 2236L, 2385L, 2619L, 2865L, 3204L,
4096L, 2306L, 1933L, 3004L, 3244L, 3513L, 3978L, 3847L, 2170L,
2112L, 3865L, 8556L, 4143L, 3300L, 3131L, 2383L, 2423L, 2934L,
4324L, 3438L, 3181L, 2552L, 2023L, 2189L, 2557L, 2687L, 3077L,
3131L, 2595L, 2544L, 2255L, 2321L, 3070L, 4986L, 4231L, 3777L,
2369L, 2137L, 3174L, 3538L, 3096L, 2918L, 2517L, 2209L, 2345L,
2765L, 2839L, 3503L, 3547L, 2994L, 1981L, 1780L, 2664L, 2617L,
383L, 2590L, 2276L, 1819L, 1524L, 2595L, 2655L, 2639L, 3849L,
4118L, 2023L, 1707L, 4849L, 4485L, 3571L, 6129L, 3345L, 3796L,
1749L, 2692L, 2602L, 3518L, 2424L, 2368L, 2366L, 2495L, 3393L,
3079L, 2926L, 3068L, 2159L, 2516L, 4885L, 5354L, 3575L, 2737L,
2797L, 2479L, 1991L, 1844L, 3451L, 5084L, 3924L, 4083L, 2817L,
2171L, 2688L, 4361L, 5857L, 4872L, 4658L, 3599L, 3272L, 3288L,
4610L, 5998L, 4051L, 3585L, 3003L, 3037L, 2874L, 3612L, 3692L,
4677L, 3935L, 2495L, 1936L, 3933L, 5173L, 3000L, 4017L, 6276L,
4662L, 3565L, 3642L, 5743L, 5297L, 5630L, 5853L, 3580L, 8417L,
4506L, 5057L, 6657L, 5561L, 4834L, 4696L, 3108L, 2814L, 6732L,
5923L, 5640L, 5705L, 4738L, 3277L, 4096L, 5164L, 5010L, 6667L,
6826L, 4637L, 3161L, 2998L, 4010L, 6037L, 6656L, 4601L, 3872L,
3263L, 3283L, 3803L, 4384L, 3008L, 3361L, 3128L, 2023L, 1957L,
4382L, 4088L, 4175L, 4624L, 3032L, 2789L, 2273L, 3345L, 3724L,
5015L, 3708L, 3505L, 3008L, 2274L, 2743L, 3294L, 4371L, 3158L,
3007L, 4219L, 3859L, 3238L, 3030L, 5063L, 5001L, 3184L, 2338L,
2676L, 2844L, 4591L, 4058L, 3284L, 2072L, 1323L, 1517L, 3573L,
4495L, 2773L, 2803L, 3664L, 2864L, 4525L, 4830L, 3901L, 3386L,
3198L, 3998L, 2477L, 2281L, 3167L, 2994L, 4391L, 4079L, 3951L,
4111L, 4174L, 6018L, 5062L, 3319L, 3644L, 3898L, 3056L, 2258L,
3418L, 3101L, 2766L, 3021L, 3097L, 3260L, 2541L, 3015L, 3068L,
3579L, 5615L, 6024L, 3544L, 4279L, 3485L, 3670L, 6398L, 5753L,
4069L, 2541L, 2256L, 2472L, 2849L, 4941L, 6027L, 6580L, 3299L,
3621L, 4608L, 5117L, 4109L, 4547L, 6919L, 7645L, 4715L, 5153L,
5915L, 4653L, 4711L, 8633L, 5522L, 5302L, 7510L, 9617L, 10461L,
8382L, 6701L, 5517L, 5467L, 4868L, 8606L, 5472L, 4702L, 3944L,
3490L, 4387L, 4968L, 4486L, 6137L, 4928L, 4191L, 3149L, 3511L,
9130L, 10724L, 10832L, 7911L, 5721L, 4824L, 7941L, 5077L, 7290L,
11041L, 18202L, 10671L, 5761L, 6211L, 7978L, 6625L, 5173L, 5715L,
7147L, 7357L, 3573L, 5490L, 5299L, 5416L, 4809L, 5494L, 3789L,
2804L, 3543L, 2972L, 2284L, 2354L, 3991L, 2356L, 2375L, 4355L,
3598L, 4654L, 4372L, 3993L, 3108L, 3080L, 3528L, 3755L, 4401L,
4272L, 2962L, 5252L, 2792L, 4034L, 3912L, 5813L, 4372L, 3205L,
3408L, 3824L, 4700L, 3707L, 3797L, 3802L, 3796L, 2830L, 4175L,
5389L, 3898L, 5583L, 5946L, 6932L, 3978L, 3678L, 5044L, 8381L,
4723L, 5084L, 4141L, 3298L, 11642L, 5766L, 7767L, 9179L, 11131L,
8179L, 6905L, 3631L, 3326L, 3467L, 2945L, 3753L, 1917L, 1336L,
1571L, 3512L, 1116L, 1251L, 1932L, 2189L, 2785L, 3161L, 3804L,
3859L, 4937L, 4200L, 10621L, 6268L, 7342L, 7001L, 5932L, 5183L,
11917L, 8051L, 9763L, 14061L, 10722L, 6173L, 5492L, 5360L, 5220L,
1108L, 1935L, 3790L, 4732L, 10167L, 7199L, 5544L, 7308L, 6308L,
6190L, 7392L, 1951L, 854L, 10228L, 11237L, 10738L, 7127L, 8779L,
8854L, 7333L, 5916L, 6135L, 8854L, 6963L, 5880L, 6865L, 7618L,
8886L, 7626L, 1355L)), class = "data.frame", row.names = c(NA,
-961L))
In the variable Freq
we find the number of times that a particular event occurs. I would like to count these numbers by month, i.e. totaling all the entries of variable Freq
by month. I tried with the following code:
library(lubridate)
aggregate(Freq~month(x), data = n_occur, sum)
but did not obtain the desired result:
month(x) Freq
1 1 317257
2 2 404837
3 3 373429
4 4 301919
5 5 339101
6 6 315882
7 7 324160
8 8 406973
9 9 243593
10 10 326444
11 11 204803
12 12 318932
I would inted like to take into account the year, for example November 2019, December 2019 and so on.
CodePudding user response:
We could extract the year, month
as grouping variable and get the sum
library(dplyr)
library(lubridate)
n_occur %>%
group_by(x = format(ymd(x), '%B %Y')) %>%
summarise(Freq = sum(Freq))
Or convert to yearmon
class from zoo
and get the sum
of 'Freq' by 'x'
library(zoo)
n_occur %>%
group_by(x = as.yearmon(x)) %>%
summarise(Freq = sum(Freq))
# A tibble: 34 × 2
x Freq
<yearmon> <int>
1 Nov 2019 1733
2 Dec 2019 137050
3 Jan 2020 114323
4 Feb 2020 115832
5 Mar 2020 51688
6 Apr 2020 17321
7 May 2020 96916
8 Jun 2020 76297
9 Jul 2020 85132
10 Aug 2020 120480
# … with 24 more rows