问题描述
我试图以01102013(2013年10月1日)的格式转换为实际的
R日期。
I'm trying to turn a date in the format of 01102013 (1st of October 2013), say, into an actualR date.
我发现一个与C#有关的类似问题,但没有R的解决方案。
I found a similar question relating to C# but no solutions for R.
我尝试了 as.Date(date,format =%d%m%Y) / code>,但是它出现了
的错误,原因是缺少(因为它是从整个日期开始的几天内读取整数,而是实际的日期,只是没有虚线或斜线) )
I tried the obvious way of as.Date(date, format=%d%m%Y)
but it came up with the error thatthe origin was missing (since it is reading the integer as a number of days since a date but it is the actual date just without dashes or slashes in between).
我还试图找到一种插入方式,或者在数字之间尝试使用R $
来识别它,但是我不能找到一种办法。
I also tried to find a way of inserting - or \ between the numbers to try and get R torecognise it but I can't find a way to do that either.
推荐答案
Lubridate为您做这件事:
Lubridate does this for you:
library(lubridate)
dmy(01102013)
这篇关于将整数字符串日期转换为实际日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!