readr not reading milliseconds correctly?

28 views
Skip to first unread message

Phillip Daves

unread,
Mar 9, 2016, 8:03:39 AM3/9/16
to manipulatr

I have a question about reading a file with read_csv. I have times that look like this with hours, minutes, seconds and milliseconds:

6:19:43.722

 

When I use read_csv in readr to read them using col_time("%H:%M:%OS") it reads hours, minutes, and seconds just fine, but there are no milliseconds. I pulled  getOption("digits.secs") to see how many digits on seconds should be displayed, but it says 3, as I’d like. 

 

When I print out what I’ve read, it looks like

         DATE  TIME_M PRICE
1  2014-01-02 6:19:43 75.10
2  2014-01-02 6:19:49 75.10
3  2014-01-02 7:00:07 75.07

 

When I assign that first time to a variable and print it, I get 22783 which is the number of seconds since midnight—so no milliseconds.

 

To confuse things, if I try:

d<-"6:19:43.722"
> strptime(d,"%H:%M:%OS")
[1] "2016-03-07 06:19:43.722 EST"

 

strptime will strip that character vector just fine… just read_csv won’t with col_time. I have a very large dataset and I'd like to read it in with time correctly so I don't have to run through it again. Any thoughts?

Thanks

Brandon Hurr

unread,
Mar 9, 2016, 9:57:43 AM3/9/16
to Phillip Daves, manipulatr
I've been reading in trouble columns in readr and readxl as text and
parsing them the way I want later. Set col_type for that column to "t"
or "text" and then parse with strptime. I typically use dplyr::mutate
for this.

Brandon
> --
> You received this message because you are subscribed to the Google Groups
> "manipulatr" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to manipulatr+...@googlegroups.com.
> To post to this group, send email to manip...@googlegroups.com.
> Visit this group at https://groups.google.com/group/manipulatr.
> For more options, visit https://groups.google.com/d/optout.

Hadley Wickham

unread,
Mar 9, 2016, 10:23:06 AM3/9/16
to Phillip Daves, manipulatr
Can you please file an issue on github if it doesn't already exist?
Hadley
> --
> You received this message because you are subscribed to the Google Groups
> "manipulatr" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to manipulatr+...@googlegroups.com.
> To post to this group, send email to manip...@googlegroups.com.
> Visit this group at https://groups.google.com/group/manipulatr.
> For more options, visit https://groups.google.com/d/optout.



--
http://hadley.nz
Reply all
Reply to author
Forward
0 new messages