0

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>     
  • Please provide a small reproducible example that shows the warning. It could be that there are only NA values for a particular group that returns Inf – akrun Aug 07 '16 at 12:47
  • Hi @akrun, I have added a few obs and yes there are only NA values for a particular group that returns Inf. This makes me think that I should first replace the NA values with some other value. Not sure what value though. – Borderlands54 Aug 07 '16 at 13:59
  • A warning message is okay. It is just a friendly warning. You can still change the `Inf` to `NA` with `%>% replace(ExitDate, is.infinite(ExitDate), NA)` – akrun Aug 07 '16 at 14:39
  • @akrun, I just tried this and received the following message: Error in replace(., ExitDate, is.infinite(ExitDate), NA) : unused argument (NA) In addition: There were 50 or more warnings (use warnings() to see the first 50) – Borderlands54 Aug 07 '16 at 14:49
  • DId you used it after the `summarise` step? Also, based on the example, I am not getting any infinite values and warning is slightly different. i.e. `Warning messages: 1: In max(NA_character_, na.rm = TRUE) : no non-missing arguments, returning NA` – akrun Aug 07 '16 at 14:51
  • @akrun Yes, I used it after the [tag:summarise] step. I'm guessing you are not getting the same warning because you are using an example that was not an imported .csv file. I imported it and used 'setAs' to coerce the date - I'm guessing this is related to the problem. – Borderlands54 Aug 07 '16 at 15:01
  • It could be that problem because I have `NA_character_` while you have `NA_real_` – akrun Aug 07 '16 at 15:01
  • @akrun any thought as to how to fix that? Should I import differently? – Borderlands54 Aug 07 '16 at 15:05
  • Try reading it without specifying the `colClasses` and then do this afterwards. – akrun Aug 07 '16 at 15:08

0 Answers0