Hello,

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 <- c("19:36:11","19:36:12","19:36:13","19:36:14","19:36:15","19:36:16")
strptime(time, "%H:%M:%S")
y<-c(197,194,189,179,166,150)
mydata<-data.frame(time=time,y=y)

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!

-Philippe

______________________________________________
R-help@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.

Reply via email to