[R] Time difference between two dates/timing

John Kane jrkrideau at inbox.com
Thu Jun 14 18:00:36 CEST 2012


First thing is to supply data in a usable form  See ?dput for one easy way of doing it.

In any case, assuming those dates and times are character values something like this should work but not tested on your data.

Assuming the data frame is called dtime

dtime[,1]  <-  strptime(dtime[,1], "%d/%m/%Y %H:%M"))
diff(dtime[,1])



John Kane
Kingston ON Canada


> -----Original Message-----
> From: antony.akkara at ge.com
> Sent: Thu, 14 Jun 2012 03:08:25 -0700 (PDT)
> To: r-help at r-project.org
> Subject: [R] Time difference between two dates/timing
> 
> Hi,
> 
> 
> Here, i have a matrix like this
> 
> MyMatrix <-
> 
> *DATETIME	 HEADER1            HEADER2*
> 1/1/2010 0:10	197.1947	             100.0859
> 1/1/2010 0:20	203.8811	             100.1013
> 1/1/2010 0:30	206.564	              100.0433
> 1/1/2010 0:40	207.9563	               99.9393
> 
> i want to get the time difference in minutes between two date.
> 
> TimeDiff <- MyMatrix[1,1] -  MyMatrix[2,1]
> TimeDiff <- 10 (need to get like this )
> 
> Could you please help me ?
> 
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Time-difference-between-two-dates-timing-tp4633353.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!



More information about the R-help mailing list