当我尝试运行以下功能时:
foo <- air_reserve %>%
mutate(reserve_date = date(reserve_datetime),
reserve_hour = hour(reserve_datetime),
reserve_wday = wday(reserve_datetime, label = TRUE),
visit_date = date(visit_datetime),
visit_hour = hour(visit_datetime),
visit_wday = wday(visit_datetime, label = TRUE),
diff_hour = time_length(visit_datetime - reserve_datetime, unit = "hour"),
diff_day = time_length(visit_datetime - reserve_datetime, unit = "day")
)
我收到以下错误:
Error in mutate_impl(.data, dots) :
Evaluation error: non-numeric argument to binary operator.
我该如何解决这个问题?
foo
函数取自此link
答案 0 :(得分:2)
哦!!
我通过以下代码解决了这个问题:
foo <- air_reserve %>%
mutate(reserve_date = date(reserve_datetime),
reserve_hour = hour(reserve_datetime),
reserve_wday = wday(reserve_datetime, label = TRUE),
visit_date = date(visit_datetime),
visit_hour = hour(visit_datetime),
visit_wday = wday(visit_datetime, label = TRUE),
diff_hour = time_length(as.numeric(visit_datetime) - as.numeric(reserve_datetime), unit = "hour"),
diff_day = time_length(as.numeric(visit_datetime) - as.numeric(reserve_datetime), unit = "day")
)