FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Difftime between Date and IDate columns · Issue #4749 · Rdatatable/data.table · GitHub

Difftime between Date and IDate columns #4749

Description

I have a data.table, full, with columns, alert_date and hosp_admsn_date.

> typeof(full[, alert_date])
[1] "double"

> typeof(full[, hosp_admsn_date])
[1] "integer"

> class(full[, alert_date])
[1] "Date"

> class(full[, hosp_admsn_date])
[1] "IDate" "Date" 

> full[, as.numeric(alert_date - hosp_admsn_date)][1:10]
 [1] 0 0 0 0 0 0 2 2 2 2
Warning message:
In eval(jsub, SDenv, parent.frame()) :
  Incompatible methods ("-.Date", "-.IDate") for "-"
  
> full[, as.numeric(alert_date - as.Date(hosp_admsn_date))][1:10]
 [1] 0 0 0 0 0 0 2 2 2 2

Note that the warning has disappeared by casting the IDate column explicitly to Date.

This is the same issue discussed in the closed 3490
Comment there stated returning to the issue if it recurred.

This code still produces a date instead of a difftime object of value 0:

> as.Date(Sys.Date()) - as.IDate(Sys.Date())
[1] "1970-01-01"
Warning message:
Incompatible methods ("-.Date", "-.IDate") for "-" 

Output of sessionInfo()

R version 4.0.2 Patched (2020-09-21 r79235)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Cairo_1.5-12.2    lattice_0.20-41   data.table_1.13.1 pacman_0.5.1     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5          pillar_1.4.6        compiler_4.0.2      RColorBrewer_1.1-2  base64enc_0.1-3     tools_4.0.2         digest_0.6.25       rpart_4.1-15        checkmate_2.0.0     htmlTable_2.0.1     lubridate_1.7.9     lifecycle_0.2.0     tibble_3.0.3        gtable_0.3.0        png_0.1-7          
[16] pkgconfig_2.0.3     rlang_0.4.7         Matrix_1.2-18       rstudioapi_0.11     xfun_0.16           gridExtra_2.3       knitr_1.29.3        cluster_2.1.0       dplyr_1.0.0         stringr_1.4.0       janitor_2.0.1       htmlwidgets_1.5.1   generics_0.0.2      vctrs_0.3.2         nnet_7.3-14        
[31] grid_4.0.2          tidyselect_1.1.0    snakecase_0.11.0    glue_1.4.1          fasttime_1.0-2      R6_2.4.1            jpeg_0.1-8.1        survival_3.2-3      foreign_0.8-80      latticeExtra_0.6-29 Formula_1.2-3       purrr_0.3.4         ggplot2_3.3.2       magrittr_1.5        htmltools_0.5.0    
[46] backports_1.1.8     Hmisc_4.4-0         scales_1.1.1        ellipsis_0.3.1      splines_4.0.2       colorspace_1.4-1    stringi_1.5.4       acepack_1.4.1       munsell_0.5.0       crayon_1.3.4       

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL