I am trying to summarize dates by ID based on the max() of ExitDate. When I run the following code, however, I receive this message:
In max.default(structure(NA_real_, class = "Date"), na.rm = TRUE) : no non-missing arguments to max; returning -Inf
I have imported the data and set the date values using setAs. Using setClass eliminated the initial warning message (as noted in another answer) but I don't know how to eliminate these other warning messages.
Any advice would be greatly appreciated!
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>