使用 R,我希望能够将格式为“2014-12-31”的日期转换为整数 20141231,以便创建序列号。
我的目标只是能够完成这个用户问题的反向(将整数字符串日期转换为实际日期 https://stackoverflow.com/questions/21117112/turning-an-integer-string-date-into-an-actual-date).
感谢所提供的任何帮助。
只需以这种方式格式化日期,然后调用as.integer
关于结果。
R> as.integer(format(Sys.Date(), "%Y%m%d"))
[1] 20151008
如果您的日期不是日期,而是字符串:要么先将其转换为日期,要么删除"-"
打电话之前as.integer
.
R> dateString <- "2014-12-31"
R> as.integer(format(as.Date(dateString), "%Y%m%d"))
[1] 20141231
R> as.integer(gsub("-", "", dateString))
[1] 20141231
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)