将数字转换为日期 [英] Convert numeric to date

查看:39
本文介绍了将数字转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将这种类型的数值转换为日期,但它不起作用.

I'd like to convert this type of numeric values to a date but it doesn't work.

20100727 例如

我尝试将数字转换为字符并应用此:

I tried to convert the numeric to character and applied this :

as.Date("20100727", "Y%d%m")

但它不起作用.

我该怎么办?

推荐答案

您设置了错误的月份和日期值顺序(在您的代码中为年、日、月,应为年、月、日).

You were setting wrong order of month and date values (in your code was Year, Date, Month, should be Year, Month, Date).

as.Date("20100727", "%Y%m%d")
[1] "2010-07-27"

这篇关于将数字转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆