简体   繁体   English

mutate_impl(.data, dots) 中的错误:评估错误:Date 类的索引只允许使用年、季度、月、周和日周期

[英]Error in mutate_impl(.data, dots) : Evaluation error: Only year, quarter, month, week, and day periods are allowed for an index of class Date

I am using Anomalize package to detect the Anomalies, but I am getting the mentioned error even though I have defined the Date as index :我正在使用Anomalize包来检测异常,但即使我已将Date定义为 index ,我也会收到上述错误:

Sample Code :示例代码:

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)

Error :错误 :

Error in mutate_impl(.data, dots) : Evaluation error: Only year, quarter, month, week, and day periods are allowed for an index of class Date. mutate_impl(.data, dots) 中的错误:评估错误: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")

I have the objective to group by date and some other factor not alone with the date.我的目标是按日期和其他一些因素进行分组,而不仅仅是日期。

I had the same issue.我遇到过同样的问题。 What helped me was to correctly define your date format:帮助我的是正确定义您的日期格式:

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

x %>% 
  as_period("daily")

From the help:从帮助:

frequency Controls the seasonal adjustment (removal of seasonality).频率控制季节性调整(去除季节性)。 Input can be either "auto", a time-based definition (eg "2 weeks"), or a numeric number of observations per frequency (eg 10).输入可以是“自动”、基于时间的定义(例如“2 周”)或每个频率的观察数值(例如 10)。 Refer to time_frequency().参考 time_frequency()。

trend Controls the trend component For stl, the trend controls the sensitivity of the lowess smoother, which is used to remove the remainder.趋势控制趋势分量对于stl,趋势控制lowess smoother的灵敏度,用于去除剩余部分。 For twitter, the trend controls the period width of the median, which are used to remove the trend and center the remainder.对于 twitter,趋势控制中位数的周期宽度,用于去除趋势并使剩余部分居中。

I think you swapped them:我想你交换了它们:

x %>%
  time_decompose(count, method = "twitter", frequency* = "2 months") %>%
  anomalize(remainder, method = "gesd") %>%
  time_recompose() %>%
  plot_anomalies(time_recomposed = TRUE)

But it's hard to tell if there are any other problems, as the data is not enough但是很难判断是否还有其他问题,因为数据不够

I was getting this error as well, until I removed duplicate dates.我也收到了这个错误,直到我删除了重复的日期。 I was trying to run the code on data that had multiple observations for each site.我试图在对每个站点有多个观察的数据上运行代码。 Once I aggrigated to single obs per day, all was well.一旦我每天聚合到单个 obs,一切都很好。

There is missing a "group_by" at this pipeline.此管道中缺少“group_by”。 This error is also in the examples of the anomalize package.这个错误也在 anomalize 包的例子中。 Error was gone after adding it.添加后错误消失。 This worked:这有效:

x %>%
  group_by(acc_id) %>%
  time_decompose(count, method = "twitter", trend = "2 months") %>%
  anomalize(remainder, method = "gesd") %>%
  time_recompose() %>%
  plot_anomalies(time_recomposed = TRUE)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mutate_impl(.data,点)中的错误:评估错误:未使用的参数 - Error in mutate_impl(.data, dots) : Evaluation error: unused argument mutate_impl(.data,点)评估错误:找不到对象 - mutate_impl(.data, dots) Evaluation error: object not found mutate_impl(.data,点)中的错误:评估错误:如果&#39;na.rm&#39;为FALSE,则不允许缺少值和NaN - Error in mutate_impl(.data, dots) : Evaluation error: missing values and NaN's not allowed if 'na.rm' is FALSE 错误代码:mutate_impl(.data,点)中的错误:评估错误:k &lt;= n不是TRUE - Error Code: Error in mutate_impl(.data, dots) : Evaluation error: k <= n is not TRUE r 编织错误:mutate_impl(.data, dots) 错误:评估错误:必须提供“来源” - r Knitting error: Error in mutate_impl(.data, dots) : Evaluation error: 'origin' must be supplied str_replace模式是“”给出“mutate_impl(.data,dots)中的错误:评估错误:未实现。” - str_replace pattern is “” gives “Error in mutate_impl(.data, dots) : Evaluation error: Not implemented.” r:mutate_impl(.data,点)中的错误:评估错误:找不到对象&#39;72L&#39; - r: Error in mutate_impl(.data, dots) : Evaluation error: object '72L' not found mutate_impl(.data,dots)出错:找不到绑定 - Error in mutate_impl(.data, dots) : binding not found 使用“ join”代码的mutate_impl(.data,点)中的错误 - Error in mutate_impl(.data, dots) using “join” code dplyr:mutate_impl(.data,点)中的错误:参数&#39;times&#39;不正确 - dplyr : Error in mutate_impl(.data, dots) : argument 'times' incorrect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM