[R] The time unit of strptime() after performing arithmetic calculation

David Winsemius dwinsemius at comcast.net
Fri Aug 9 19:55:41 CEST 2013


On Aug 9, 2013, at 10:37 AM, Jun Shen wrote:

> Hi all,
> 
> I used strptime() to convert character strings to time and did some
> subtraction calculation.
> 
> a<-'2012-07-17T07:50'
> b<-'2012-08-27T09:30'
> 
> strptime(a,format='%Y-%m-%dT%H:%M')-strptime(b,format='%Y-%m-%dT%H:%M')
> 
> The result shows
> 
> Time difference of -41.06944 days.
> 
> However when these operations performed in a dataframe, the time difference
> is in the unit of seconds. Why is that? What I really want is in hours. I
> know I can convert the results manually to hours but just wonder if there
> is way to control the unit. Thanks.

?difftime
?`-.POSIXt`

Should provide exactly what is requested (and is linked from the ?DateTimeClasses help page.)

-- 
David Winsemius
Alameda, CA, USA



More information about the R-help mailing list