Re: [Rd] as.POSIXct behaviour

2017-03-08 Thread Suzen, Mehmet
On 9 March 2017 at 01:29, Arunkumar Srinivasan
 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.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

[Rd] as.POSIXct behaviour

2017-03-08 Thread Arunkumar Srinivasan
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.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel