It's hard for us to help since we cannot reproduce your data. To facilitate this, you need to provide a reproducible example (or reprex for short). You can learn how to make one by following this guide.
Thanks siddharthprabhu for your help.
My problem is not a error. I downloaded a data in days from 2002 Gen to 2020 october, i want to download a monthly frequency in the same period.
For example i used this code:
library(readxl)
library(BatchGetSymbols)
library(rvest)
library(xml2)
library(quantmod)
library(foreign)
library(xts)
library(ggplot2)
library(rsq)
library(pastecs)
Reprexes are not just for errors. They allow others to reconstruct a sample of your data. That is very handy when it comes to figuring out an appropriate solution.
Since I don't know what your data looks like, I'll make up some of my own and illustrate how to aggregate it. You can adapt it to your needs.
library(dplyr, warn.conflicts = FALSE)
library(lubridate, warn.conflicts = FALSE)
df <- tibble::tribble(~date, ~value,
"2002-01-02", 20,
"2002-01-05", 50,
"2002-01-07", 35,
"2002-02-03", 10,
"2002-02-08", 70,
"2003-01-16", 10,
"2003-01-25", 90) %>%
mutate(date = as.Date(date))
df %>%
group_by(year = year(date), month = month(date, label = TRUE)) %>%
summarise(total_value = sum(value))
#> `summarise()` regrouping output by 'year' (override with `.groups` argument)
#> # A tibble: 3 x 3
#> # Groups: year [2]
#> year month total_value
#> <dbl> <ord> <dbl>
#> 1 2002 Jan 105
#> 2 2002 Feb 80
#> 3 2003 Jan 100