EdwinTh / padr

Padding of missing records in time series
https://edwinth.github.io/padr/
Other
132 stars 12 forks source link

Error on long unsorted timestamps #53

Closed sobradob closed 6 years ago

sobradob commented 6 years ago

Thanks again for the project.

I cannot figure out exactly where its falling apart, but here's an issue with long unsorted timestamps. I'd be happy to send over the data if it helps, but I cannot figure out how to get a succinct reproducible example.

# this fails 
mDaily %>%
  thicken('day') %>%
  group_by(time_day) %>%
  summarise(count = n()) %>%
  pad() %>%
  fill_by_value(value = 0)

Error in if (!all(dt_var[1:(length(dt_var) - 1)] <= dt_var[2:length(dt_var)])) { : 
  missing value where TRUE/FALSE needed
In addition: Warning message:
In if (unique(nchar(x_char)) == 10) { :
  the condition has length > 1 and only the first element will be used

# this works

mDaily %>% top_n(nrow(mDaily))%>% 
  thicken('day') %>%
  group_by(time_day) %>%
  summarise(count = n()) %>%
  pad() %>%
  fill_by_value(value = 0)

sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252 
[2] LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] bindrcpp_0.2 padr_0.3.0   dplyr_0.7.4 

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13     lubridate_1.6.0  assertthat_0.2.0 R6_2.2.2        
 [5] magrittr_1.5     rlang_0.1.2      stringi_1.1.5    tools_3.4.2     
 [9] stringr_1.2.0    glue_1.2.0       yaml_2.1.14      compiler_3.4.2  
[13] pkgconfig_2.0.1  bindr_0.1        tibble_1.3.4    
EdwinTh commented 6 years ago

This is because your datetime variable contains missing values. Most likely the top_n function filtered the missing values from the dataframe. In v.0.4.0 both thicken and pad allow your datetime variable to have missing values. You can already grab this version with devtools::intstall_github("EdwinTh/padr").