执行`floor_date()`时出错 [英] Error when executing `floor_date()`

查看:45
本文介绍了执行`floor_date()`时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误消息:

Error in if (sum(c(new$hour, new$min, new$sec))) { : 
  argument is not interpretable as logical

当我执行以下代码时:

keep$EstimateDate <- as.Date(keep$date + keep$days,"%Y-%m-%d")
keep$EstimateDateWeekStart <- floor_date(keep$EstimateDate,"week") #+1

keep$EstimateDate是data.table中的列,其日期格式正确.

The keep$EstimateDate is a column in a data.table with properly formatted dates.

floor_date()lubridate包中的函数.

推荐答案

我能想到的唯一情况是,当您拥有NA时,在if中出现错误但在sum中没有出现错误用你的钱.考虑到这一点,这很可能是正在发生的事情:

The only scenario I can think of where you get an error in if but don't in sum, is when you have an NA in your sum. With that in mind, this is most likely what's happening:

floor_date(as.Date(NA), "week")
#Error in if (sum(c(new$hour, new$min, new$sec))) { : 
#  argument is not interpretable as logical

换句话说,请检查您是否没有任何NA.

In other words, check that you don't have any NA's.

这篇关于执行`floor_date()`时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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