gpt4 book ai didi

r - 如何替换 R 中日期对象中的天数?

转载 作者:行者123 更新时间:2023-12-05 08:30:36 27 4
gpt4 key购买 nike

<分区>

我想将 R 中 Date 对象中的不同日期替换为所有对象的同一天。

让我们举个例子。

date = structure(c(10961, 10990, 11018, 11046, 11060, 11088, 11116, 
11144, 11214, 11235, 11249, 11263, 11305, 11354, 11382, 11423,
11452, 11480, 11494, 11508), class = "Date")

[1] "2000-01-05" "2000-02-03" "2000-03-02" "2000-03-30" "2000-04-13" "2000-05-11" "2000-06-08"
[8] "2000-07-06" "2000-09-14" "2000-10-05" "2000-10-19" "2000-11-02" "2000-12-14" "2001-02-01"
[15] "2001-03-01" "2001-04-11" "2001-05-10" "2001-06-07" "2001-06-21" "2001-07-05"

我想得到:

 [1] "2000-01-05" "2000-02-05" "2000-03-05" "2000-03-05" "2000-04-05" "2000-05-05" "2000-06-05"
[8] "2000-07-05" "2000-09-05" "2000-10-05" "2000-10-05" "2000-11-05" "2000-12-05" "2001-02-05"
[15] "2001-03-05" "2001-04-05" "2001-05-05" "2001-06-05" "2001-06-05" "2001-07-05"

我做的是:


sub("%d", "05", date, perl = TRUE)

但是,它不起作用。我认为错误在 pattern 中,我不知道如何把握这一天。

谁能帮帮我?

谢谢!

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com