[R] Calculating difference in variable values (e.g. elapsed time) in data frame

Philippe Hensel Philippe.Hensel at noaa.gov
Thu Jul 28 17:38:42 CEST 2011


I have a data frame containing time (e.g. GMT), and I would like to 
create/add a new variable that would be the computation of the elapsed 
time since the first observation.  Does anyone have a suggestion for an 
easy way to do this?  I am having trouble creating a new variable that 
would contain just the first time observation (then I could take 
difference between actual time and initial time).

e.g. - here's a brief representation of the data:

time <-  
strptime(time, "%H:%M:%S")

OK, now how do I create a new variable, say, time_el, that would 
calculate the elapsed time since 19:36:11?  I assume that I need the 
strptime() function to make sure R treats the character strings as time.

Thank you very much for any & all assistance!


More information about the R-help mailing list