So I have a series of values in two columns in this format

6/14/1998 17:30 | 6/16/1998 1:45

I would like to calculate the time between this two timestamps in R.

Basically, calculate the number of hours between t1 and t2. Could you please help?

Thanks!

有帮助吗?

解决方案

Elementary, and covered a million times:

R> difftime(strptime("6/16/1998 01:45", "%m/%d/%Y %H:%M", tz="UTC"),
+           strptime("6/14/1998 17:30", "%m/%d/%Y %H:%M", tz="UTC"),
+           unit="min")     
Time difference of 1935 mins
R> 

See help(difftime) and help(strptime).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top