首页 > 解决方案 > Filter_time 函数 - 在 R 中过滤时间

问题描述

我正在尝试根据 R Bloggers 的这个博客进行一些时间序列预测。 使用 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 。我遇到了同样的错误。

我怎么能避免这个错误。

问候,任。

标签: r

解决方案


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

require(lubridate)

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

推荐阅读