Hi I have two columns of data with time in form of HH:MM:SS - representing start time and end time of an activity. I am trying to calculate the time difference (duration of the activity). (1) I first tried> difftime(btime, etime, units = "mins")This however gave me the error - Error in as.POSIXlt.character(as.character(x)) : character string is not in a standard unambiguous format (2) The above error message indicated some problem in format. So I tried> etime1=as.date(etime, %H:%M:%S")This gave me the Error: unexpected SPECIAL in "etime1=as.date(etime, %H:%" I also tried>etime1=format(etime, %H:%M:%S")But this gave a similar error - unexpected SPECIAL in "etime1=format(etime, %H:%" Any suggestions? Regards [[alternative HTML version deleted]]
You seem to have omitted a left quotation mark in (2): %H:%M:%S". Regards, Yihui -- Yihui Xie <xieyihui at gmail.com> Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China On Sun, Oct 5, 2008 at 1:25 PM, Gouri Shankar Mishra <gouri.mishra at gmail.com> wrote:> Hi > > I have two columns of data with time in form of HH:MM:SS - representing > start time and end time of an activity. I am trying to calculate the time > difference (duration of the activity). > > (1) I first tried >> difftime(btime, etime, units = "mins") > This however gave me the error - Error in > as.POSIXlt.character(as.character(x)) : character string is not in a > standard unambiguous format > > (2) The above error message indicated some problem in format. So I tried >> etime1=as.date(etime, %H:%M:%S") > This gave me the Error: unexpected SPECIAL in "etime1=as.date(etime, %H:%" > > I also tried >>etime1=format(etime, %H:%M:%S") > But this gave a similar error - unexpected SPECIAL in "etime1=format(etime, > %H:%" > > Any suggestions? > > Regards > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Seems to work fine for me:> times <- c("10:12:34", "14:23:15") > Ptime <- as.POSIXct(strptime(times, "%H:%M:%S")) > > Ptime[1] "2008-10-05 10:12:34 GMT" "2008-10-05 14:23:15 GMT"> difftime(Ptime[2], Ptime[1], units='min')Time difference of 250.6833 mins>You just have to be careful that all your times are for the same day since you do not have a 'date' associated with the time. On Sun, Oct 5, 2008 at 1:25 AM, Gouri Shankar Mishra <gouri.mishra at gmail.com> wrote:> Hi > > I have two columns of data with time in form of HH:MM:SS - representing > start time and end time of an activity. I am trying to calculate the time > difference (duration of the activity). > > (1) I first tried >> difftime(btime, etime, units = "mins") > This however gave me the error - Error in > as.POSIXlt.character(as.character(x)) : character string is not in a > standard unambiguous format > > (2) The above error message indicated some problem in format. So I tried >> etime1=as.date(etime, %H:%M:%S") > This gave me the Error: unexpected SPECIAL in "etime1=as.date(etime, %H:%" > > I also tried >>etime1=format(etime, %H:%M:%S") > But this gave a similar error - unexpected SPECIAL in "etime1=format(etime, > %H:%" > > Any suggestions? > > Regards > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Apparently Analagous Threads
- [PATCH 03/23] drm/i915: Don't use struct drm_driver.get_scanout_position()
- Samba/Netscape Directory Server
- [PATCH 01/23] drm: Add get_scanout_position() to struct drm_crtc_helper_funcs
- ETIME on FreeBSD
- [PATCH 02/23] drm/amdgpu: Convert to struct drm_crtc_helper_funcs.get_scanout_position()