[R] time question

David Winsemius dwinsemius at comcast.net
Tue Nov 9 15:30:55 CET 2010


On Nov 9, 2010, at 9:18 AM, Ralf B wrote:

> I have this script which I use to get an epoch with accuracy of 1
> second (based on R's inability to calculate millisecond-accurate
> timestamps -- at least I have not seen a straightforward solution :)
> ):

 From help page for Sys.time:

"Value
Sys.time returns an object of class "POSIXct" (see DateTimeClasses).  
On almost all systems it will have sub-second accuracy: on systems  
conforming to POSIX 1003.1-2001 the time will be reported in  
microsecond increments. On Windows it increments in clock ticks (1/60  
of a second) reported to millisecond accuracy."



You may be misled by the output of default formats.



>
> nowInSeconds <- as.numeric(Sys.time())
> nowInMS <- nowInSeconds * 1000
> print(nowInSeconds)
> print(as.character(nowInMS))
>
> when running this I get the following:
>
>> nowInSeconds <- as.numeric(Sys.time())
>> nowInMS <- nowInSeconds * 1000
>> print(nowInSeconds)
> [1] 1289312002
>> print(as.character(nowInMS))
> [1] "1289312002093"
>
>
> I wonder where the 93 milliseconds come from. Is this a random number?
> A rounding error? Can somebody explain this?
>
> Best,
> Ralf

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list