My weekly dataset has different state_id associated with different cities.Value1 and value2 need to be aggregated to monthly level and then quarterly level.So am trying below code:
library(dplyr)
df <- dataset %>%
group_by(state_id,city_id) %>%
group_by(three_month = round_date(weekly_dt, "quarter")) %>%
summarise_at(vars(starts_with('value')), mean)
But its popping out this error
Error in mutate_impl(.data, dots) :
Column `three_month` must be length 1 (the group size), not 3766742
Note : All cities don't have same level of weekly data that is the reason I used group_by first. Can someone help me in R. EDIT :my dat
structure(list(city_id = c("B02", "B02", "B02",
"B02", "B02", "B02"), state_id = c(609L, 609L,
609L, 609L, 609L, 609L), weekly_dt = structure(c(17601,
17545, 17447, 17727, 17510, 17664), class = "Date"), value1 = c(0.194669883125,
0.35, 0.35, 0.124875972916667, 0.35, 0.140909438125), value2 = c(0.203018924883721,
0.35, 0.35, 0.35, 0.35, 0.35)), class = c("data.table", "data.frame"
), row.names = c(NA, -6L), .internal.selfref = <pointer: 0x0000000004541ef0>)