[R] Mystified - comparing chron times
bps0002 at auburn.edu
Fri Sep 16 16:08:43 CEST 2011
I'm sure Sarah's solution works (and she knows more about R than myself), but
I ran into a similar problem and used:
good luck regardless.
Sarah Goslee wrote:
> Sounds like a case for FAQ 7.31, or, yet another machine precision issue.
> Try all.equal() instead of ==
> On Fri, Sep 16, 2011 at 7:36 AM, mebstyne <mebstyne at me.com> wrote:
>> I have two local variables: startTime and expectedStartTime. Both are
>> related objects.
>> When I look at the class for the objects I can see they are of class
>> When I print them to the console, they both read: "09:30:00"
>> When I print them as.numeric(), they both read: 0.3958333
>> When I try and compare them: (as.numeric(startTime) ==
>> as.numeric(expectedStartTime)) it returns FALSE.
>> I'm mystified. I would expect them to be true.
>> Perhaps a key to the riddle is how the two objects were created.
>> "startTime" was created by reading a text field from a socket, converting
>> into a chron object using chron(x, "%m/$d/%Y %H:%M:%S"), then finally I
>> created a time out of the chron by doing a quick butchering of the
>> portion of the numeric: (times(as.numeric(x) - as.integer(x))
>> "expectedStartTime" was created by the command times('09:30:00')
>> Any suggestions? Tips? Alternative approaches? I've pulled too many
>> triaging this.
>> All hands welcomed on this little challenge.
>> Big picture goal of what I'm doing: I have a list of chron objects with
>> dates and times portion filled out and I'm trying to determine if the
>> is a specific time (specific to the minute).
> Sarah Goslee
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
View this message in context: http://r.789695.n4.nabble.com/Mystified-comparing-chron-times-tp3817855p3818176.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help