【问题标题】:Anomalize error: no date or datetime column found异常化错误:未找到日期或日期时间列
【发布时间】:2018-04-24 17:51:36
【问题描述】:

我有一些数据:

   dput(y)
structure(list(date = structure(c(1508803200, 1515456000, 1506384000, 
1501027200, 1503964800, 1517356800, 1519776000, 1511740800, 1511827200, 
1498521600, 1509408000, 1522627200, 1493078400, 1502064000, 1504051200, 
1504569600, 1504742400, 1512432000, 1515628800, 1520467200, 1493164800, 
1496102400, 1496620800, 1501459200, 1506988800, 1508889600, 1512864000, 
1515542400, 1515974400, 1517443200, 1520553600, 1520812800, 1494806400, 
1495756800, 1496188800, 1496707200, 1498608000, 1499040000, 1499299200, 
1501113600, 1501200000, 1502150400, 1504656000, 1507075200, 1508976000, 
1509235200, 1509494400, 1515369600, 1516752000, 1516838400, 1517961600, 
1518393600, 1519689600, 1522368000, 1522540800), class = c("POSIXct", 
"POSIXt")), word = c("hr", "hr", "hr", "hr", "hr", "hr", "hr", 
"hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", 
"hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", 
"hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", 
"hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", "hr", 
"hr", "hr", "hr", "hr"), n = c(22L, 16L, 14L, 8L, 8L, 6L, 6L, 
5L, 5L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
)), row.names = c(NA, -55L), vars = "date", drop = TRUE, class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), .Names = c("date", "word", "n"
), indices = list(12L, 20L, 32L, 33L, 21L, 34L, 22L, 35L, 9L, 
    36L, 37L, 38L, 3L, 39L, 40L, 23L, 13L, 41L, 4L, 14L, 15L, 
    42L, 16L, 2L, 24L, 43L, 0L, 25L, 44L, 45L, 10L, 46L, 7L, 
    8L, 17L, 26L, 47L, 1L, 27L, 18L, 28L, 48L, 49L, 5L, 29L, 
    50L, 51L, 52L, 6L, 19L, 30L, 31L, 53L, 54L, 11L), group_sizes = c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L), biggest_group_size = 1L, labels = structure(list(
    date = structure(c(1493078400, 1493164800, 1494806400, 1495756800, 
    1496102400, 1496188800, 1496620800, 1496707200, 1498521600, 
    1498608000, 1499040000, 1499299200, 1501027200, 1501113600, 
    1501200000, 1501459200, 1502064000, 1502150400, 1503964800, 
    1504051200, 1504569600, 1504656000, 1504742400, 1506384000, 
    1506988800, 1507075200, 1508803200, 1508889600, 1508976000, 
    1509235200, 1509408000, 1509494400, 1511740800, 1511827200, 
    1512432000, 1512864000, 1515369600, 1515456000, 1515542400, 
    1515628800, 1515974400, 1516752000, 1516838400, 1517356800, 
    1517443200, 1517961600, 1518393600, 1519689600, 1519776000, 
    1520467200, 1520553600, 1520812800, 1522368000, 1522540800, 
    1522627200), class = c("POSIXct", "POSIXt"))), row.names = c(NA, 
-55L), vars = "date", drop = TRUE, class = "data.frame", .Names = "date"))

和代码:

y = y %>% 
  group_by(date) %>%
  unnest_tokens(word,comments) %>%
  anti_join(stop_words) %>%
  count(word,sort = T) 


  y %>% time_decompose(count,method='stl')%>%
    anomalize(remainder,method = 'iqr') %>%
    time_recompose()%>% plot_anomalies(time_recomposed = T,ncol=5,alpha_dots = 0.25)

除了我不断收到以下错误:

mutate_impl(.data, dots) 中的错误:评估错误:prep_tbl_time() 中的错误:未找到日期或日期时间列..

我为此遵循了 github 教程,并且我的列和类型与示例相匹配。但由于某种原因,它找不到列日期。

【问题讨论】:

  • 哪个line causes the error?你能dput(head(y))你的数据框的开头,所以我们可以check where the error occurs for ourselves吗?您的语法还表明打印的 y 是在完成一些处理之后,而不是管道开始之前的原始数据帧(请参阅第 1 行中 rename 的使用,这表明原始数据具有列 @987654328 @ 而不是date。)
  • 你想用第一部分完成什么?它正在那里发生,但我无法确定。
  • 我最近遇到了这个问题,这是由从 Github 安装的旧版本的 anomalize 引起的。从 CRAN 重新安装最新版本(连同依赖项)解决了这个问题。

标签: r tidyverse


【解决方案1】:

这是一个笨蛋。几周前我完成了该教程,所以我将您的数据与tidyverse_cran_downloads 进行比较,我看不出有什么区别。它可能在任何时候都不像POSIX 那样喜欢日期,但我真的不明白这有什么关系。我还使用您相同布局中的组成数据运行它并且它有效。希望这会有所帮助。

counts <- data.frame(date = as.Date(c("2013-09-13", "2014-01-23", "2014-06-24", "2017-04-25", "2017-04-26", "2017-06-28", "2017-09-26")), word = c("hr", "hr", "hr", "hr", "hr", "hr", "hr"), count = c(2, 6, 2, 3, 2, 4, 4), stringsAsFactors = FALSE)

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

counts %>% 
time_decompose(count, method = "stl") %>% 
anomalize(remainder) %>% 
time_recompose() %>% 
plot_anomalies(time_recomposed = TRUE, ncol = 3, alpha_dots = 0.5)

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,在我的情况下,group_bytime_decompose 之前提供了帮助:

    y %>% group_by(word) %>%
        time_decompose(count,method='stl')%>%
        anomalize(remainder,method = 'iqr') %>%
        time_recompose()%>% plot_anomalies(time_recomposed = T,ncol=5,alpha_dots = 0.25)
    

    【讨论】:

      猜你喜欢
      • 2017-01-28
      • 2011-03-28
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 2023-04-02
      • 2020-09-18
      • 2018-03-14
      相关资源
      最近更新 更多