Dear all, I have ran a simulation in R. This simulation was running about at least two days. Here is below the result some part of my code about time result. I don't understand about Start time: Mon Oct 24, 2005 at 04:23:01 PM Finish time: Wed Oct 26, 2005 at 03:26:19 PM Run time: 1.960625 secs. This is about two seconds or one day and nine hours? Then, how could I convert to 1 day, 23 hours, ? minutes, ? seconds. Thanks you very much for any suggestions. Best wishes, Muhammad Subianto > ################################################################################ > # Begin of program and timestamp: > cat(format(begin.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") Mon Oct 24 04:23:01 PM 2005 > cat("Start time:", secs <- format(begin.time, "%X"), "\n") Start time: 04:23:01 PM > cat("Sys.time:", begin.time <- Sys.time(), '\n') Sys.time: 1130163781 > > --- CODE SIMULATION --- > > # End of program and timestamp: > cat("Sys.time:",end.time <- Sys.time(), '\n') Sys.time: 1130333179 > cat("Run Time:",end.time-begin.time, 'secs.\n\n') Run Time: 1.960625 secs. > cat("Finish time:", secs <- format(end.time, "%X"), "\n") Finish time: 03:26:19 PM > cat(format(end.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") Wed Oct 26 03:26:19 PM 2005 > > cat("\n", + " Start time:", secs <- format(begin.time, "%a %b %d, %Y at %X"), "\n", + "Finish time:", secs <- format(end.time, "%a %b %d, %Y at %X"), "\n", + " Run time:", end.time-begin.time, 'secs.\n\n') Start time: Mon Oct 24, 2005 at 04:23:01 PM Finish time: Wed Oct 26, 2005 at 03:26:19 PM Run time: 1.960625 secs. > ###########################################################################
Those are obviously days, not seconds. A simple test would have answered your question: test <- strptime("20051026 15:26:19",format="%Y%m%d %H:%M:%S") - strptime("20051024 16:23:01",format="%Y%m%d %H:%M:%S") class(test) test cat(test,"\n") If you prefer you can use difftime for conversion: difftime(strptime("20051026 15:26:19",format="%Y%m%d %H:%M:%S"), strptime("20051024 16:23:01",format="%Y%m%d %H:%M:%S"),units="hours")> -----Original Message----- > From: Muhammad Subianto [mailto:subianto at gmail.com] > Sent: Wednesday, October 26, 2005 10:18 AM > To: R-help at stat.math.ethz.ch > Subject: [R] How to convert time to days > > > Dear all, > I have ran a simulation in R. > This simulation was running about at least two days. > Here is below the result some part of my code about time result. > I don't understand about > > Start time: Mon Oct 24, 2005 at 04:23:01 PM > Finish time: Wed Oct 26, 2005 at 03:26:19 PM > Run time: 1.960625 secs. > > This is about two seconds or one day and nine hours? > Then, how could I convert to 1 day, 23 hours, ? minutes, ? seconds. > Thanks you very much for any suggestions. > > Best wishes, Muhammad Subianto > > > > ############################################################## > ################## > > # Begin of program and timestamp: > > cat(format(begin.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") > Mon Oct 24 04:23:01 PM 2005 > > cat("Start time:", secs <- format(begin.time, "%X"), "\n") > Start time: 04:23:01 PM > > cat("Sys.time:", begin.time <- Sys.time(), '\n') > Sys.time: 1130163781 > > > > > --- CODE SIMULATION --- > > > > # End of program and timestamp: > > cat("Sys.time:",end.time <- Sys.time(), '\n') > Sys.time: 1130333179 > > cat("Run Time:",end.time-begin.time, 'secs.\n\n') > Run Time: 1.960625 secs. > > > cat("Finish time:", secs <- format(end.time, "%X"), "\n") > Finish time: 03:26:19 PM > > cat(format(end.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") > Wed Oct 26 03:26:19 PM 2005 > > > > cat("\n", > + " Start time:", secs <- format(begin.time, "%a %b %d, %Y at > %X"), "\n", > + "Finish time:", secs <- format(end.time, "%a %b %d, %Y at > %X"), "\n", > + " Run time:", end.time-begin.time, 'secs.\n\n') > > Start time: Mon Oct 24, 2005 at 04:23:01 PM > Finish time: Wed Oct 26, 2005 at 03:26:19 PM > Run time: 1.960625 secs. > > > > ############################################################## > ############# > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
The word "secs" appears in "Run time: 1.960625 secs" because you put it there in your cat() statement. It has nothing to do with the number itself. Simply try typing end.time - begin.time at the prompt, and see what you get. Then see ?difftime for more information. Example difftime(end.time,begin.time,units='hours') To get the interval formatted as "1 day, 23 hours, x minutes, x seconds" you will have to do more work. -Don At 4:18 PM +0200 10/26/05, Muhammad Subianto wrote:>Dear all, >I have ran a simulation in R. >This simulation was running about at least two days. >Here is below the result some part of my code about time result. >I don't understand about > >Start time: Mon Oct 24, 2005 at 04:23:01 PM > Finish time: Wed Oct 26, 2005 at 03:26:19 PM > Run time: 1.960625 secs. > >This is about two seconds or one day and nine hours? >Then, how could I convert to 1 day, 23 hours, ? minutes, ? seconds. >Thanks you very much for any suggestions. > >Best wishes, Muhammad Subianto > > > >################################################################################ > > # Begin of program and timestamp: > > cat(format(begin.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") >Mon Oct 24 04:23:01 PM 2005 > > cat("Start time:", secs <- format(begin.time, "%X"), "\n") >Start time: 04:23:01 PM > > cat("Sys.time:", begin.time <- Sys.time(), '\n') >Sys.time: 1130163781 > > > > >--- CODE SIMULATION --- > > > > # End of program and timestamp: > > cat("Sys.time:",end.time <- Sys.time(), '\n') >Sys.time: 1130333179 > > cat("Run Time:",end.time-begin.time, 'secs.\n\n') >Run Time: 1.960625 secs. > > > cat("Finish time:", secs <- format(end.time, "%X"), "\n") >Finish time: 03:26:19 PM > > cat(format(end.time <- Sys.time(), "%a %b %d %X %Y") ,"\n") >Wed Oct 26 03:26:19 PM 2005 > > > > cat("\n", >+ " Start time:", secs <- format(begin.time, "%a %b %d, %Y at >%X"), "\n", >+ "Finish time:", secs <- format(end.time, "%a %b %d, %Y at >%X"), "\n", >+ " Run time:", end.time-begin.time, 'secs.\n\n') > > Start time: Mon Oct 24, 2005 at 04:23:01 PM > Finish time: Wed Oct 26, 2005 at 03:26:19 PM > Run time: 1.960625 secs. > > > >########################################################################### > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA