[R] Package to manipulate timestamp data in format HH:MM:SS:sss
jim holtman
jholtman at gmail.com
Thu Sep 12 22:03:23 CEST 2013
Use POSIXct for the date/time stamp. For your data you will have to
substitute a period ('.') for the last colon (":"), but that is easy
to do with 'sub'.
You will get millisecond precision, but just barely; don't try for
microseconds since for that is the limit of precision with floating
point number representing the number of seconds from 1/1/1970 till now
(10 digits before the decimal and 4-5 after). Here is an example:
> x <- "12:52:48:123"
> x1 <- sub("(.*):", "\\1.", x) # replace last colon
> x1
[1] "12:52:48.123"
> xp <- as.POSIXct(x1, format="%H:%M:%OS")
> xp # normal output
[1] "2013-09-12 12:52:48 EDT"
> format(xp, format = "%H:%M:%OS3") # with milliseconds
[1] "12:52:48.122"
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
On Thu, Sep 12, 2013 at 1:26 PM, Alecia M Moser <amoser1 at binghamton.edu> wrote:
> Hello -
>
> I have imported timestamp data (collected in OpenSHAPA) into R as .csv
> file. Some columns in the data frame have timestamps in the format
> HH:MM:SS:sss. I have not found a package that will allow simple addition
> and subtraction of columns with this format, although 'strptime' in
> 'library(timeDate)' looked promising. The problem with the timeDate package
> is that it does not seem to support timestamps down to milliseconds. Are
> there any solutions available or packages that the community recommends?
> Thanks you.
>
> Alecia
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list