[R] difftime on vector

jim holtman jholtman at gmail.com
Thu Sep 15 15:59:33 CEST 2011


You need to supply two vectors:

> x <- seq(Sys.time(), by = '10 min', length = 10)
> x
 [1] "2011-09-15 09:58:30 EDT" "2011-09-15 10:08:30 EDT" "2011-09-15
10:18:30 EDT"
 [4] "2011-09-15 10:28:30 EDT" "2011-09-15 10:38:30 EDT" "2011-09-15
10:48:30 EDT"
 [7] "2011-09-15 10:58:30 EDT" "2011-09-15 11:08:30 EDT" "2011-09-15
11:18:30 EDT"
[10] "2011-09-15 11:28:30 EDT"
> difftime(head(x, -1), tail(x, -1))
Time differences in mins
[1] -10 -10 -10 -10 -10 -10 -10 -10 -10
>


On Thu, Sep 15, 2011 at 8:42 AM, bradford <fingermark at gmail.com> wrote:
> How can I apply difftime to a vector of sorted dates?  I can do this just
> fine with diff, but difftime doesn't seem to take in a vector.
>
>> diff(r$BOOKING_DATE)
> Works.  Great!
>
>> difftime(r$MY_DATE, units="days")
> Error in as.POSIXct(time2) : argument "time2" is missing, with no default
>
> Thanks,
> Bradford
>
>        [[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
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list