Quantcast

as.POSIXct behaviour

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

as.POSIXct behaviour

Arunkumar Srinivasan-2
Dear R-devel, I have tested the code below on R v3.3.2 and v3.3.3 on
Mac and Windows.

x <- c("2017-01-01 05:00:02", "2017-01-02 03 :M:00") # note the ‘ :M’
in 2nd value
as.POSIXct(x)
# [1] "2017-01-01 GMT" "2017-01-02 GMT”

The time info is lost on the first index as well. And it happens *silently*.

On the other hand, if I do:

lapply(x, as.POSIXct)
# [[1]]
# [1] "2017-01-01 05:00:02 GMT"
#
# [[2]]
# [1] "2017-01-02 GMT”

A list is returned, but values are as I’d expect. Would it be possible
to retain the time info with as.POSIXct(x) directly as well? If not,
what’s the rationale? In addition, I think a warning message that some
malformed timestamps were found would be very useful.

Thank you,
Arun.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: as.POSIXct behaviour

Suzen, Mehmet
On 9 March 2017 at 01:29, Arunkumar Srinivasan
<[hidden email]> wrote:
> The time info is lost on the first index as well. And it happens *silently*.

Yes, because it assumes homogeneous format on the entire vector.  You
may want to
do  two passes with different formats or run a regular expression to
catch typos.

> lapply(x, as.POSIXct)
> A list is returned, but values are as I’d expect. Would it be possible
> to retain the time info with as.POSIXct(x) directly as well? If not,

This behaves differently because you are running as.POSIXct for each element
separately.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Loading...