Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (5.3k points)

How do I use strptime or any other functions to parse timestamps with milliseconds in R?

time[1]

# [1] "2010-01-15 13:55:23.975"

strptime(time[1], format="%Y-%m-%d %H:%M:%S.%f")

# [1] NA

strptime(time[1], format="%Y-%m-%d %H:%M:%S")

# [1] "2010-01-15 13:55:23"`

1 Answer

0 votes
by

You can use the options function to set the digits for fractional seconds as follows:

z <- strptime("2010-01-15 13:55:23.975", "%Y-%m-%d %H:%M:%OS")

 z

[1] "2010-01-15 13:55:23.975 IST"                                       # prints without fractional seconds

def <- options(digits.secs=3)

z

[1] "2010-01-15 13:55:23.975 IST"

options(def)   #to reset options

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...