如何根据其索引间隔更改日期Posixct列的年份?
我的数据看起来像这样:
> dput(head(nAUR,50))
structure(list(date = structure(c(1483440272, 1484304241, 1484564041,
1484823831, 1485428001, 1485687791, 1486032161, 1486291941, 1486551731,
1486896101, 1487155881, 1487415671, 1487760031, 1488019821, 1488279601,
1488624021, 1488883821, 1489143521, 1489488011, 1489747821, 1490007451,
1490352021, 1490608221, 1490867781, 1491212421, 1491472221, 1491731811,
1492076421, 1492336231, 1492595781, 1492940421, 1493200231, 1493459811,
1493804421, 1494064231, 1494323781, 1494668431, 1494928231, 1495187811,
1495532431, 1495792231, 1496051781, 1496396421, 1496656231, 1496915811,
1497260421, 1497520231, 1497779781, 1498124421, 1498384231), tzone = "", class = c("POSIXct",
"POSIXt")), layer = c("AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR")), row.names = c(NA,
-50L), class = c("tbl_df", "tbl", "data.frame"))
我想更改2017-01-13之间的日期 10:44:01(1484304241),直到2017-03-17 10:50:21(14897477821)到 2016 。我必须使用数据框中的位置间隔(索引)进行此操作,因为在我的原始数据集中,我要更改的那些日期都重复了。
任何帮助将不胜感激。
My data looks like this:
> dput(head(nAUR,50))
structure(list(date = structure(c(1483440272, 1484304241, 1484564041,
1484823831, 1485428001, 1485687791, 1486032161, 1486291941, 1486551731,
1486896101, 1487155881, 1487415671, 1487760031, 1488019821, 1488279601,
1488624021, 1488883821, 1489143521, 1489488011, 1489747821, 1490007451,
1490352021, 1490608221, 1490867781, 1491212421, 1491472221, 1491731811,
1492076421, 1492336231, 1492595781, 1492940421, 1493200231, 1493459811,
1493804421, 1494064231, 1494323781, 1494668431, 1494928231, 1495187811,
1495532431, 1495792231, 1496051781, 1496396421, 1496656231, 1496915811,
1497260421, 1497520231, 1497779781, 1498124421, 1498384231), tzone = "", class = c("POSIXct",
"POSIXt")), layer = c("AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR",
"AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR", "AUR")), row.names = c(NA,
-50L), class = c("tbl_df", "tbl", "data.frame"))
I want to change the YEAR of the dates between 2017-01-13 10:44:01 (1484304241) until 2017-03-17 10:50:21 (1489747821) to 2016. I have to do it using their position interval in the dataframe (index) because in my original data set those dates I want to change are repeated.
Any help will be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
`年< - `()()
lubridate 替换DateTime对象的年份。更新
You could use
`year<-`()
fromlubridate
to replace the year of a datetime object.Update