自定义tsibble年月栏的显示格式?

问题描述 投票:0回答:1

可以自定义tsibble中时间序列栏的显示格式吗?

yearmonth 总是喜欢 %Y %m,但我想将默认格式更改为 %m-%y 全部在一个块上

tsibble::格式不工作

r time series tsibble yearmonth
1个回答
0
投票

也许你正在寻找

format('%b-%Y')
?

df <- data.frame(
  date = c("2022-01-01","2022-02-01","2022-03-01",
           "2022-04-01","2022-05-01","2022-06-01","2022-07-01",
           "2022-08-01","2022-09-01","2022-10-01","2022-11-01","2022-12-01")
)

df |>
  dplyr::mutate(
    date = tsibble::yearmonth(date) |>
      format('%b-%Y')
  )
#>        date
#> 1  Jan-2022
#> 2  Feb-2022
#> 3  Mar-2022
#> 4  Apr-2022
#> 5  May-2022
#> 6  Jun-2022
#> 7  Jul-2022
#> 8  Aug-2022
#> 9  Sep-2022
#> 10 Oct-2022
#> 11 Nov-2022
#> 12 Dec-2022

创建于 2023-04-19 与 reprex v2.0.2

© www.soinside.com 2019 - 2024. All rights reserved.