0

工作示例:

library(fpp3)

Data <- aus_retail %>%
  filter(State == "Western Australia",
         Industry == "Takeaway food services")

autoplot(Data) + xlim()

我将如何做一些事情,比如限制 x 轴或过滤数据,以便只存储 2000 年之后的日期?不确定如何使用 tsibble 的 yearmonth 变量。

谢谢!

4

1 回答 1

0

您可以使用year函数 fromlubridate从对象中提取年份yearmonth并仅保留 2000 年之后的数据。

library(dplyr)
library(lubridate)

tsibbledata::aus_retail %>%
  filter(State == "Western Australia",
         Industry == "Takeaway food services") %>%
  filter(year(Month) >= 2000)

#   State             Industry               `Series ID`    Month Turnover
#   <chr>             <chr>                  <chr>          <mth>    <dbl>
# 1 Western Australia Takeaway food services A3349435A   2000 Jan     61  
# 2 Western Australia Takeaway food services A3349435A   2000 Feb     56  
# 3 Western Australia Takeaway food services A3349435A   2000 Mar     61.1
# 4 Western Australia Takeaway food services A3349435A   2000 Apr     64.2
# 5 Western Australia Takeaway food services A3349435A   2000 May     65.7
# 6 Western Australia Takeaway food services A3349435A   2000 Jun     64.9
# 7 Western Australia Takeaway food services A3349435A   2000 Jul     62.6
# 8 Western Australia Takeaway food services A3349435A   2000 Aug     62.8
# 9 Western Australia Takeaway food services A3349435A   2000 Sep     62.1
#10 Western Australia Takeaway food services A3349435A   2000 Oct     66.6
# … with 218 more rows
于 2021-09-24T03:52:05.033 回答