[R] Strange behaviour when using diff with POSIXt and POSIXlt objects

jim holtman jholtman at gmail.com
Thu May 20 18:55:49 CEST 2010


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?



More information about the R-help mailing list