[R] using difftime()

steve012 stephenadrake at gmail.com
Mon Apr 5 15:19:37 CEST 2010


I'm new to R and have the following problem with difftime:

if I directly assign date/time strings in difftime I get the expected
result:

> a<-"2010-03-23 10:52:00"
> a
[1] "2010-03-23 10:52:00"
> b<-"2010-03-23 11:53:00"
> u2<-as.difftime(c(a,b), format ="%Y-%m-%d %H:%M:%S", units="mins")
> u2
Time differences in mins
[1] -18008 -17947
attr(,"tzone")


However, if I first assign the values of "a" and "b" from a data frame
within a loop I get a different result:

a<-u[i]
> a
[1] 2010-03-23 10:52:00
6838 Levels: 2010-03-18 16:54:00 2010-03-18 16:55:00 ... 2010-03-23 11:53:00
b<-u[i+1]
> b
[1] 2010-03-23 11:53:00
6838 Levels: 2010-03-18 16:54:00 2010-03-18 16:55:00 ... 2010-03-23 11:53:00
u2<-as.difftime(c(a,b), format ="%Y-%m-%d %H:%M:%S", units="mins")
> u2
Time differences in mins
[1] 6837 6838


So, how do use difftime in the context of a loop? Thanks.
-- 
View this message in context: http://n4.nabble.com/using-difftime-tp1751607p1751607.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list