如何修改 lubridate 函数中的 dmy() 以输出 1900 年代而不是 2000 年代?
How can I modify dmy() in lubridate function to output the 1900s instead of the 2000s?
我的数据只显示年份的最后两位数字。使用
dmy("090965")
输出是“2065-09-09”。
我希望它是“1965-09-09”。我如何修改它以获得输出?
一种做事方式:
a=dmy("090965")
year(a)=1965
# or if you have a vector with multiple years:
year(a)=year(a)-100
> a
[1] "1965-09-09"
我遇到了另一种可能的解决方案,以防您要求日期开始的截止年份。只是想更新这个以防我将来需要它。这仅适用于 1900 年代和 2000 年代
# if you require dates after 1908
parse_date_time2("090965", "dmy", cutoff_2000 = 8L)
# if you require dates after 1960
> parse_date_time2("090965", "dmy", cutoff_2000 = 60L)
[1] "1965-09-09 UTC"
# if you require dates after 1970
> parse_date_time2("090965", "dmy", cutoff_2000 = 70L)
[1] "2065-09-09 UTC"
我的数据只显示年份的最后两位数字。使用
dmy("090965")
输出是“2065-09-09”。
我希望它是“1965-09-09”。我如何修改它以获得输出?
一种做事方式:
a=dmy("090965")
year(a)=1965
# or if you have a vector with multiple years:
year(a)=year(a)-100
> a
[1] "1965-09-09"
我遇到了另一种可能的解决方案,以防您要求日期开始的截止年份。只是想更新这个以防我将来需要它。这仅适用于 1900 年代和 2000 年代
# if you require dates after 1908
parse_date_time2("090965", "dmy", cutoff_2000 = 8L)
# if you require dates after 1960
> parse_date_time2("090965", "dmy", cutoff_2000 = 60L)
[1] "1965-09-09 UTC"
# if you require dates after 1970
> parse_date_time2("090965", "dmy", cutoff_2000 = 70L)
[1] "2065-09-09 UTC"