Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

summarise issue with POSIXct #1622

Closed
restonslacker opened this issue Jan 15, 2016 · 2 comments
Closed

summarise issue with POSIXct #1622

restonslacker opened this issue Jan 15, 2016 · 2 comments
Assignees

Comments

@restonslacker
Copy link

@restonslacker restonslacker commented Jan 15, 2016

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

.

@romainfrancois romainfrancois self-assigned this Jan 25, 2016
@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Jan 27, 2016

Fixed now, but beware that it might not do what you expect.

df %>%
   group_by(event) %>% 
   summarise(FIRST_DAY=min(FIRST_DAY), LAST_DAY=max(FIRST_DAY))

The FIRST_DAY used in max(FIRST_DAY) is the already summarized variable, i.e. the result of min(FIRST_DAY)

Loading

@restonslacker
Copy link
Author

@restonslacker restonslacker commented Jan 27, 2016

Thank you!

And I'm completely fine with that behavior. After I wrote the code I realized that LAST_DAY = max(min(FIRST_DAY)) should probably be the correct interpretation of what I wrote and fixed it in my actual code. But since I saw the other behavior, I still wanted to report it, even if the example seemed a little goofy.

Loading

@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants