restonslacker · GitHub

The issue here is that LAST_DAY column should be a POSIXct object and not an int (as opposed to what the value of LAST_DAY should be, 2015-12-01 or -02).

library(dplyr)
library(magrittr)
df <- data.frame(FIRST_DAY=rep(seq(as.POSIXct("2015-12-01", tz="UTC"), length.out=2, by="days"),2),
                 event=c("a","a","b","b"))
df %>% group_by(event) %>% summarise(FIRST_DAY=min(FIRST_DAY), LAST_DAY=max(FIRST_DAY)) -> df_summary
df_summary
#> Source: local data frame [2 x 3]
#> 
#>    event  FIRST_DAY   LAST_DAY
#>   (fctr)     (time)      (int)
#> 1      a 2015-12-01 1448928000
#> 2      b 2015-12-01 1448928000
min(df$FIRST_DAY)
#> [1] "2015-12-01 UTC"
max(df$FIRST_DAY)
#> [1] "2015-12-02 UTC"
max(min(df$FIRST_DAY))
#> [1] "2015-12-01 UTC"
sessionInfo()
#> R version 3.2.3 (2015-12-10)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows >= 8 x64 (build 9200)
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.1252 
#> [2] LC_CTYPE=English_United States.1252   
#> [3] LC_MONETARY=English_United States.1252
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] magrittr_1.5      dplyr_0.4.3.9000  reprex_0.0.0.9001
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_0.12.3          assertthat_0.1       digest_0.6.9        
#>  [4] R6_2.1.1             DBI_0.3.1            formatR_1.2.1       
#>  [7] evaluate_0.8         httr_1.0.0           stringi_1.0-1       
#> [10] lazyeval_0.1.10.9000 curl_0.9.4           rmarkdown_0.9.2     
#> [13] devtools_1.9.1       tools_3.2.3          stringr_1.0.0       
#> [16] parallel_3.2.3       rsconnect_0.4.1.4    clipr_0.2.0         
#> [19] memoise_0.2.1        htmltools_0.3        knitr_1.12

.

Read the original on github.com ↗