mutate_impl(.data,点)中的错误:评估错误:类Date的索引只允许年,季度,月,周和日的时间段

Raj*_*Raj 3 r time-series dplyr anomaly-detection tidyverse

我正在使用Anomalize包检测异常,但是即使定义了Dateas索引,也遇到了上述错误:

样例代码:

x <- as.data.frame(data %>%
  group_by(date,acc_id) %>%
  summarise(count = as.numeric(n_distinct(d_id))) %>%
  ungroup())

x$acc_id <- as.character(x$acc_id)

x <- x %>% 
  tibbletime::as_tbl_time(index = date)


x %>%
  time_decompose(count, method = "twitter", trend = "2 months") %>%
  anomalize(remainder, method = "gesd") %>%
  time_recompose() %>%
  plot_anomalies(time_recomposed = TRUE)
Run Code Online (Sandbox Code Playgroud)

错误:

mutate_impl(.data,点)中的错误:评估错误:类Date的索引只允许年,季度,月,周和日的时间段。

dput(head(x))

structure(list(date = structure(c(17532, 17532, 17532,  17532, 17532, 17532), class = "Date"), acc_id = c("a44444",  "gg555", "0195459b-5809-4b54-89b5-1a4376c9f126",  "ggg6546", "hhjh77",  "hhjh68777"), count = c(3, 1, 1, 1,  1, 1)), .Names = c("date", "acc_id", "count"), row.names = c(NA, 
-6L), class = c("tbl_time", "tbl_df", "tbl", "data.frame"), index_quo = ~date, index_time_zone = "UTC")
Run Code Online (Sandbox Code Playgroud)

我的目标是按日期分组,而不是仅按日期分组。

Sly*_*yrs 5

我遇到过同样的问题。帮助我的是正确定义您的日期格式:

library(tibbletime)
x <- as_tbl_time(x, index = date)

x %>% 
  as_period("daily")
Run Code Online (Sandbox Code Playgroud)