【发布时间】:2020-08-03 07:10:07
【问题描述】:
我使用 read_excel 从 Excel 中读取一个数组,得到两个日期时间列,但我需要的是两列日期
User DOB Answer_dt Question Answer
<chr> <dttm> <dttm> <int> <int>
1 User1 1900-01-01 00:00:00 2017-01-26 00:00:00 1 7
2 User2 1900-01-01 00:00:00 2017-01-26 00:00:00 2 8
我希望将 datetime 列转换为日期(时间无关紧要),并尝试在各种组合中使用 mutate 和 lubridate,但仅成功收到我不明白的错误消息:
> library(lubridate)
> dt <- eML_daily[1, "DOB"]
> dt
# A tibble: 1 x 1
DOB
<dttm>
1 1900-01-01 00:00:00
Warning message:
`...` is not empty.
These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
> as_date(dt)
Error in as.Date.default(x, ...) :
do not know how to convert 'x' to class “Date”
> as_date(df[,"DOB"])
Error in as.Date.default(x, ...) :
do not know how to convert 'x' to class “Date”
我不理解警告信息,也不太明白我做错了什么。当然,从 dttm 转换为 date 并丢弃我不需要的时间应该是一件简单的事情。
我会非常感谢指针。
在此致以诚挚的谢意
托马斯·飞利浦
【问题讨论】:
-
能否提供
dput()格式的数据?请访问this。