Filter_time函数-在R中过滤时间

时间:2018-06-28 17:28:51

标签: r

我正在尝试根据R Bloggers的博客进行一些时间序列预测。 Time Series Forecasting using keras

这是我尝试使用的代码。

# Core Tidyverse
library(tidyverse)
library(glue)
library(forcats)
library(dplyr)

# Time Series
library(timetk)
library(tidyquant)
library(tibbletime)
library(stats)

# Visualization
library(cowplot)

# Preprocessing
library(recipes)

# Sampling / Accuracy
library(rsample)
library(yardstick) 

# Modeling
library(keras)
library(tfruns)

#reading excel file

library("readxl")
incoming_volume <- read_excel(file.choose())

volume <- incoming_volume %>%
  tk_tbl() %>%
  mutate(index = as_date(index)) %>%
  as_time(index = index)

p1 <- volume %>%
  ggplot(aes(index, value)) +
  geom_point(color = palette_light()[[1]], alpha = 0.5) +
  theme_tq() +
  labs(
    title = "From July 2011 to May 2018 "
  )

p2 <- volume %>%
  filter_time("start" ~ "2011") %>%
  ggplot(aes(index, value)) +
  geom_line(color = palette_light()[[1]], alpha = 0.5) +su
  geom_point(color = palette_light()[[1]]) +
  geom_smooth(method = "loess", span = 0.2, se = FALSE) +
  theme_tq() +
  labs(
    title = "2011 to 2018 (Zoomed In To Show Changes over the Year)",
    caption = "Incoming Volume"
  )

我收到一条错误消息,指出找不到filter_time函数。 我也尝试过time_filter。我遇到了同样的错误。

如何避免此错误。

关于, 仁。

1 个答案:

答案 0 :(得分:0)

您可以通过以下方式更改“ filter_time”:

require(lubridate)

p2 <- volume %>%
      filter(year(as.Date(index)) > 2011)