On Sun, May 1, 2011 at 15:33, Joel Reymont <joelr1 at gmail.com>
wrote:>
> Does R have support for microseconds in timestamps, e.g. when reading this
in
>
> "Time","Include","Kind","Duration"
> 2011-04-01 14:20:36.368324,Y,U,1.03238296509
> 2011-04-01 14:20:35.342732,Y,C,0.0252721309662
> 2011-04-01 14:20:34.337209,Y,R,0.00522899627686
>
See ?strptime:
Specific to R is %OSn, which for output gives the seconds to 0 <= n <= 6
decimal places (and if %OS is not followed by a digit, it uses the setting of
getOption("digits.secs"), or if that is unset, n = 3). Further, for
strptime
%OS will input seconds including fractional seconds. Note that %S ignores
(and not rounds) fractional parts on output.
dat <- read.table(textConnection(
'"Time","Include","Kind","Duration"
2011-04-01 14:20:36.368324,Y,U,1.03238296509
2011-04-01 14:20:35.342732,Y,C,0.0252721309662
2011-04-01 14:20:34.337209,Y,R,0.00522899627686'),
header=TRUE, sep=",")
R> dat$Time <- as.POSIXct(dat$Time, "%Y-%m-%d %H:%M:%OS6")
R> dat$Time
[1] "2011-04-01 14:20:36.368" "2011-04-01 14:20:35.343"
[3] "2011-04-01 14:20:34.337"
R> options(digits.secs=6)
R> dat$Time
[1] "2011-04-01 14:20:36.368324" "2011-04-01
14:20:35.342732"
[3] "2011-04-01 14:20:34.337209"
R> class(dat$Time)
[1] "POSIXct" "POSIXt"
HTH,
Rainer