我一定很遗憾 .
我有一个各种日期格式的data.frame,我正在使用lubridate,除了 month names by themselves 之外的所有东西都很好用 . 我无法将月份名称转换为日期时间对象 .
> head(dates)
From To
1 June August
2 January December
3 05/01/2013 10/30/2013
4 July November
5 06/17/2013 10/14/2013
6 05/04/2013 11/23/2013
试图将June更改为date time对象:
> as_date(dates[1,1])
Error in charToDate(x) :
character string is not in a standard unambiguous format
> as_date("June")
Error in charToDate(x) :
character string is not in a standard unambiguous format
- 实际年和日无所谓 . 我只需要一个月 . zx8754建议使用虚拟日和年 .
2 回答
使用自定义功能:
以下是如何实现这一目标的粗略示例 .
假设虚拟值很好:
鉴于
dates[1. 1]
中有Dec
,上述内容将返回给您:为了生成上面的返回值以及日期格式的虚拟数字,我试过:
这给了我们:
最后:
返回:
我相信有比这更灵活的方法;但这只是一个想法,我刚试过 .