Вопрос

I get the following error message:

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

when I execute the following code:

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

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

The floor_date() is a function in the lubridate package.

Это было полезно?

Решение

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

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top