[R] Strange behaviour when using diff with POSIXt and POSIXlt objects
Brian Diggs
diggsb at ohsu.edu
Thu May 20 22:15:47 CEST 2010
On 5/20/2010 9:59 AM, Julian Burgos wrote:
> Hi Jim
>
> I´m using R 2.11.0, on Windows XP.
For what it is worth, it works fine for me, too. R 2.11.0 on Windows XP
Pro. My gut instinct is to check that time3 and time4 are really what
you think they are. If that is not it, post the results of dput(time3),
dput(time4), and sessionInfo().
time3=strptime("2009 06 01 00 47 00",format="%Y %m %d %H %M")
time4=strptime("2009 06 01 00 57 00",format="%Y %m %d %H %M")
diff(c(time3,time4))
#Time difference of 10 mins
sessionInfo()
#R version 2.11.0 (2010-04-22)
#i386-pc-mingw32
#
#locale:
#[1] LC_COLLATE=English_United States.1252
#[2] LC_CTYPE=English_United States.1252
#[3] LC_MONETARY=English_United States.1252
#[4] LC_NUMERIC=C
#[5] LC_TIME=English_United States.1252
#
#attached base packages:
#[1] stats graphics grDevices utils datasets methods base
> On Thu, May 20, 2010 at 4:55 PM, jim holtman<jholtman at gmail.com> wrote:
>
>> Please provide information as to what version you are using; works fine
>> for me:
>>
>>> time3=strptime("2009 06 01 00 47 00",format="%Y %m %d %H %M")
>>> time4=strptime("2009 06 01 00 57 00",format="%Y %m %d %H %M")
>>>
>>> diff(c(time3,time4))
>> Time difference of 10 mins
>>>
>>
>> I have version 2.10.1
>>
>> On Thu, May 20, 2010 at 12:36 PM, Julian Burgos<jmburgos at uw.edu> wrote:
>>> Dear list,
>>>
>>> I´m calculating time differences between series of time stamps and I
>> noticed
>>> something odd:
>>>
>>> If I do this...
>>>
>>>> time1=strptime("2009 05 31 22 57 00",format="%Y %m %d %H %M")
>>>> time2=strptime("2009 05 31 23 07 00",format="%Y %m %d %H %M")
>>>>
>>>> diff(c(time1,time2),units="mins")
>>> Time difference of 10 mins
>>>
>>> .. I get the correct response in minutes. But if I try the same thing
>> with
>>> different values, say..
>>>
>>>> time3=strptime("2009 06 01 00 47 00",format="%Y %m %d %H %M")
>>>> time4=strptime("2009 06 01 00 57 00",format="%Y %m %d %H %M")
>>>>
>>>> diff(c(time3,time4))
>>> Time difference of NA secs
>>>
>>> ...which is not what I´m looking for. The difference should also be 10
>>> minutes.
>>>
>>> I burned a few neurons (and searched the documentation) and I cannot
>> figure
>>> why this happens. Any ideas?
>>>
>>> All the best,
>>>
>>> Julian
>>>
>>> Julian Mariano Burgos
>>> Hafrannsóknastofnunin/Marine Research Institute
>>> Skúlagata 4, 121 Reykjavík, Iceland
>>> Sími/Telephone : +354-5752037
>>> Bréfsími/Telefax: +354-5752001
>>> Netfang/Email: julian at hafro.is, jmburgos at uw.edu
>>>
>>> [[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.
>>>
>>>
>>
>>
>>
>> --
>> Jim Holtman
>> Cincinnati, OH
>> +1 513 646 9390
>>
>> What is the problem that you are trying to solve?
>>
>
>
>
--
Brian Diggs
Senior Research Associate, Department of Surgery, Oregon Health &
Science University
More information about the R-help
mailing list