Hello,

I have been attempting to write a script that automatically calculates time
intervals from a list of hh.mm.ss.ms timestamps. Should be easy, but I keep
running into problems. Any help would be greatly appreciated!!

Problems:
1. If I parse the timestamp, it doesn't always return the digits after the
decimal
2. If I subtract .5 - .955 (as in 19:22:0.5 - 19:21:59.955), then I get a
really big negative number

Here is sample data:

 19:21:59.855
 19:21:59.905
 19:21:59.955
 19:22:0.5
 19:22:0.55
 19:22:0.105
 19:22:0.155
 19:22:0.205
 19:22:0.255
 19:22:0.305
 19:22:0.355
 19:22:0.405

Here is my code:

#attempts to parse milliseconds from timestamp
for (i in 1:200){k[i] =
rbind(substring(TimeStamp[i,3],8:10)[which(substring(TimeStamp[i,3],8:10)<1)])}

#attempts to intelligently subtract intervals
for (i in 1:200){if(as.numeric(k[(i+1)])>as.numeric(k[(i)])){k2[i] =
rbind(as.numeric(k[(i+1)])-as.numeric(k[(i)]))}else{k2[i] =
rbind((1+as.numeric(k[(i+1)]))-as.numeric(k[(i)]))}}

Thanks so much for your help!!!

Best,

Dave Deriso
UCSD Psychiatry

        [[alternative HTML version deleted]]

______________________________________________
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