您如何使用R中使用橄榄酸软件包的日期提取年份?
尝试在列reign_start上使用ymd()函数,但给予 错误AS:
Warning: All formats failed to parse. No formats found.
[1] NA
中的年份表示。
Tried using ymd() function on the column reign_start but give
error as:
Warning: All formats failed to parse. No formats found.
[1] NA
The years are represented in B.C.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ymd()
用于将日期的字符表示转换为类date
的变量, yyyy-mm-dd 。您的日期已经是类日期
。您想要的
lubridate
函数是Year()
。我不确定如何处理BC日期,但我认为您希望0026-01-16
返回26
。因此,尝试
年(reign_start)
。以下是一些需要ymd()
首先(您的数据没有)的示例。ymd()
is for converting character representations of dates into variables of classDate
with formatYYYY-MM-DD
. Your dates are already of classDate
.The
lubridate
function you want isyear()
. I'm not sure how that handles BC dates but I assume you would like0026-01-16
to return26
.So try
year(reign_start)
. Here are some examples which do requireymd()
first (your data doesn't).