0

我正在尝试根据 ExitDate 的 max() 按 ID 汇总日期。但是,当我运行以下代码时,我会收到此消息:

在 max.default(structure(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>     
4

0 回答 0