0

When I convert my time-date column (dateWw) to POSIXct (column dateW) the first 2 rows become duplicates and the odd milliseconds in my original column become even (e.g. row 3 and 4).

options(digits.secs=5)
jalpy$dateW <- as.POSIXct(jalp$dateWw, format = "%Y-%m-%d %H:%M:%OS", tz="GMT") 
> head(jalpy)
  dateWw                 dateW                 depth
1 2016-06-15 02:09:27.00 2016-06-15 02:09:27.00 0.0900
2 2016-06-15 02:09:27.01 2016-06-15 02:09:27.00 0.0898
3 2016-06-15 02:09:27.05 2016-06-15 02:09:27.04 0.0894
4 2016-06-15 02:09:27.09 2016-06-15 02:09:27.08 0.0890
5 2016-06-15 02:09:27.16 2016-06-15 02:09:27.16 0.0884
6 2016-06-15 02:09:27.20 2016-06-15 02:09:27.20 0.0880
> str(jalpy)
'data.frame':   872976 obs. of  3 variables:
 $ dateWw: chr  "2016-06-15 02:09:27.00" "2016-06-15 02:09:27.01" "2016-06-15 02:09:27.05" "2016-06-15 02:09:27.09" ...
 $ dateW : POSIXct, format: "2016-06-15 02:09:27.00" "2016-06-15 02:09:27.00" "2016-06-15 02:09:27.04" ...
 $ depth : num  0.09 0.0898 0.0894 0.089 0.0884 ...
> 

I have tried converting my data to POSIXct from epoch time, POSIXlt and using the lubridate package but they all produce the same outcome.

Just wondering if anyone has come across this before and knows a solution?

Thanks!

Grace

Grace Sutton
  • 113
  • 10
  • `jalpy` is not `jalp` - are you sure this isn't just a typo on your behalf? – thelatemail Apr 03 '17 at 03:53
  • It's interesting that `diff(jalp$dateW)` gives the expected differences (0.00999, 0.03999, 0.03999...), even if the displayed representation does not. – r2evans Apr 03 '17 at 03:58
  • It is not duplicating the first row: `as.POSIXct("2016-06-15 02:09:27.01", format="%Y-%m-%d %H:%M:%OS", tz="GMT")` displays `"...27.00"`. It appears the issue may be that the *displayed* timestamp is not correct. Try: `as.POSIXct("2016-06-15 02:09:27.01", format="%Y-%m-%d %H:%M:%OS", tz="GMT") - as.POSIXct("2016-06-15 02:09:27.00", format="%Y-%m-%d %H:%M:%OS", tz="GMT")` and you'll see that though the printed formats are identical, there is in fact a difference. – r2evans Apr 03 '17 at 04:03
  • Thanks @r2evans. It's a bit of a relief that my data isn't stuffing up, still doesn't explain why the printed formats are identical. Maybe POSIX doesn't like showing odd numbers? – Grace Sutton Apr 03 '17 at 04:16
  • My *guess* is that it's related to [R FAQ 7.31](https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f), relating to floating-point numbers. On your `"...27.01"` timestamp, try changing it to `"...27.010001"` and you'll see that the output now appears correct, suggesting a low-order rounding issue. (Part of me is still confused why `options(digits.secs=99)` (too high) doesn't result in `"...27.00999"` or `"...27.01000"`; change that, I'm frustrated that the extra digits are being suppressed. \*shrug\*) – r2evans Apr 03 '17 at 04:22

0 Answers0