I have a data frame with page impressions for the last year of different URLs.
colnames(gsm)
[1] "path" "date" "impressions"
I want to group the date df bypath
and add a time series to each group. I tried this:
library(dplyr)
library(zoo)
path_metrics = gsm %>% group_by(path, date) %>% mutate(date=as.Date(date)) %>% mutate(ts = zoo(date, clicks))
I got this error message:
Problem with
mutate()
input..1
. x “value” : attempt to assign invalid coredata to zoo object Input..1
iszoo(date, impressions)
. The error occurred in group 9: path = "/foo/", date = 2021-05-08
Here is the error trace:
<error/dplyr:::mutate_error>
Problem with `mutate()` input `..1`.
x indexes overlap
ℹ Input `..1` is `zoo(date, clicks)`.
ℹ The error occurred in group 600: date = "2021-05-25".
Backtrace:
█
1. ├─`%>%`(...)
2. ├─dplyr::mutate(., zoo(date, clicks))
3. ├─dplyr:::mutate.data.frame(., zoo(date, clicks))
4. │ └─dplyr:::mutate_cols(.data, ...)
5. │ ├─base::withCallingHandlers(...)
6. │ ├─base::withCallingHandlers(...)
7. │ └─vctrs::vec_unchop(chunks <- vec_cast_common(!!!chunks), rows)
8. ├─vctrs:::base_c_invoke(...)
9. │ └─vctrs:::base_c(xs)
10. │ └─rlang::exec("c", !!!xs, .env = ns_env("base"))
11. ├─base::c(...)
12. ├─zoo:::c.zoo(...)
13. │ └─zoo::rbind.zoo(...)
14. │ └─base::stop("indexes overlap")
15. └─base::.handleSimpleError(...)
16. └─dplyr:::h(simpleError(msg, call))
<error/simpleError>
indexes overlap
How can I get a group df with containing time series?
In the next step I want to compare the impressions of each URL find those that have same senonality.