我试图根据ExitDate的max()按ID汇总日期。但是,当我运行以下代码时,收到此消息:
在max.default中(结构(NA_real_,class =“Date”),na.rm = TRUE): max没有非缺失的参数;返回-Inf
我已导入数据并使用setAs设置日期值。使用setClass消除了初始警告消息(如另一个答案中所述),但我不知道如何消除这些其他警告消息。
非常感谢任何建议!
setClass("myDate")
setAs("character", "myDate", function(from)
as.Date(from, format = "%m/%d/%Y"))
prog <- read.csv("Program.csv",
stringsAsFactors = FALSE,
colClass = c("EntryDate" = "myDate",
"ExitDate" = "myDate",
"DateUpdated"= "myDate")
prog2 <- prog %>%
group_by(id, EntryDate) %>%
summarize(new_exit = as.Date(max(ExitDate, na.rm = TRUE), origin ="1970-01-01")) %>%
right_join(prg, by = c("id", "EntryDate"))
id EntryDate ExitDate
1 5 2014-10-06 <NA>
2 5 2014-02-05 2014-02-21
3 3 2014-02-05 2014-02-28
4 3 2014-09-30 2014-11-25
5 3 2014-11-25 <NA>
6 4 2014-10-03 <NA>