EdwinTh / padr

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

Error in charToDate(x) #82

Closed bonushenricus closed 3 years ago

bonushenricus commented 3 years ago

Hi Edwin I have a problem with the pad function When I work with data of this format

Date[1:1], format: "2021-05-15"

gives me this error

Error in charToDate(x) : character string is not in a standard unambiguous format

Thank you

EdwinTh commented 3 years ago

Thank you for using padr. Would you be so kind to create a reprex (https://reprex.tidyverse.org/), so I can reproduce the error and figure out what is wrong? Thanks!

bonushenricus commented 3 years ago

Hi Edwin I canceled what I had done because I thought I would work differently here's how I worked now (sorry is it essential to use reprex?) `

variable monitoring time

tempo <- as.POSIXct(c("2021-05-29 17:00:00 UTC","2021-06-05 10:52:00 UTC","2021-06-01 17:00:00 UTC","2021-05-16 08:34:00 UTC","2021-06-05 17:00:00 UTC","2021-05-29 05:30:00 UTC","2021-05-23 06:30:00 UTC","2021-05-20 13:00:00 UTC","2021-05-15 12:09:00 UTC","2021-06-06 19:18:00 UTC"))

variable capture of BMSB

catture <- c(25,92,23,2,5,30,23,3,15,21,15,40,22)

resulting table

library(data.table) arvaia_catture <- data.table(tempo,catture)

order by time

arvaia_catture_order <- arvaia_catture[order(arvaia_catture$tempo)]

calculate the rate per hour of capture

arvaia_catture_order$difftime_ora <- c(0,diff(arvaia_catture_order$tempo)) arvaia_catture_order$catture_ora <- arvaia_catture_order$catture/arvaia_catture_order$difftime_ora

use of padr to fill the gap

library(padr) arvaia_catture_ora <- thicken(arvaia_catture_order,interval = "hour") pad(arvaia_catture_ora,by=arvaia_catture_ora$tempo_hour) ` there is this similar error

Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format

bonushenricus commented 3 years ago

the "tempo_hour" is in the format "%Y-%m-%d %H:%M:%S tz" with tz CEST (so Europe/Rome) but if I try Sys.setenv(TZ='UTC') and I work with UTC the problem is the same

EdwinTh commented 3 years ago

I see. The by argument takes a character string to indicate which column to use. Instead you are feeding it a vector. You should use:

pad(arvaia_catture_ora, by = 'tempo')

Looking at it this is not entirely obvious from the docs, I will file an issue to improve this. Also, we could throw an informative error if this happens.