因为它按记录运行。使用基础 R 中的精细文档help(strptime)
:
‘%U’ Week of the year as decimal number (00-53) using Sunday as
the first day 1 of the week (and typically with the first
Sunday of the year as day 1 of week 1). The US convention.
‘%V’ Week of the year as decimal number (01-53) as defined in ISO
8601. If the week (starting on Monday) containing 1 January
has four or more days in the new year, then it is considered
week 1. Otherwise, it is the last week of the previous year,
and the next week is week 1. (Accepted but ignored on
input.)
[...]
‘%W’ Week of the year as decimal number (00-53) using Monday as
the first day of week (and typically with the first Monday of
the year as day 1 of week 1). The UK convention.
然后我们可以通过%Y-W
以下选项进行测试:
> strftime(as.Date("2020-01-01"), "%Y-W%U")
[1] "2020-W00"
> strftime(as.Date("2020-01-01"), "%Y-W%V")
[1] "2020-W01"
> strftime(as.Date("2020-01-01"), "%Y-W%W")
[1] "2020-W00"
>
您在示例中获得的内容本质上只是围绕相同功能的包装器。也许yearweek()
给你一个约定的选择;如果不是,您现在知道如何在不同的选项下构建自己的。