Christine SINOQUET
2011-Jan-15 11:57 UTC
[R] access to right time unit when checking for time execution
Hello, I really wonder how to distinguish between secs and mins in the example below. In other terms, how can I access the time unit in variable d ? start1 <- Sys.time(); stop1 <- Sys.time(); d <- stop1-start1; print(d); v<-unlist(strsplit(as.character(d), split=" ")); print(v) Time difference of 3.024054 secs [1] "3.02405381202698" stop1 <- Sys.time(); d <- stop1-start1; print(d); v <- unlist(strsplit(as.character(d), split=" ")); print(v) Time difference of 3.189143 mins [1] "3.18914334774017" Thank you in advance for your kind help. C.S.
Uwe Ligges
2011-Jan-15 14:45 UTC
[R] access to right time unit when checking for time execution
On 15.01.2011 12:57, Christine SINOQUET wrote:> Hello, > > I really wonder how to distinguish between secs and mins in the example > below. > > In other terms, how can I access the time unit in variable d ? > > start1 <- Sys.time(); > stop1 <- Sys.time(); d <- stop1-start1; print(d); > v<-unlist(strsplit(as.character(d), split=" ")); print(v) > Time difference of 3.024054 secs > [1] "3.02405381202698">> stop1 <- Sys.time(); d <- stop1-start1; print(d); > v <- unlist(strsplit(as.character(d), split=" ")); print(v) > Time difference of 3.189143 mins > [1] "3.18914334774017"1. If you want to measure execution time, use system.time(). 2. If you want to calculate a time difference, use difftime() and specify the unit: difftime(stop1, start1, units="mins") Best, Uwe Ligges> > Thank you in advance for your kind help. > > C.S. > > ______________________________________________ > 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.
David Winsemius
2011-Jan-15 14:47 UTC
[R] access to right time unit when checking for time execution
On Jan 15, 2011, at 6:57 AM, Christine SINOQUET wrote:> Hello, > > I really wonder how to distinguish between secs and mins in the > example below. > > In other terms, how can I access the time unit in variable d ? > > start1 <- Sys.time(); > stop1 <- Sys.time(); d <- stop1-start1;> str(d) Class 'difftime' atomic [1:1] 0.00343 ..- attr(*, "units")= chr "secs" > attr(d, "units") [1] "secs"> print(d); v<-unlist(strsplit(as.character(d), split=" ")); print(v) > Time difference of 3.024054 secs > [1] "3.02405381202698" > > stop1 <- Sys.time(); d <- stop1-start1;# Wait a bit... > d Time difference of 1.053085 mins > stop1 <- Sys.time(); d <- stop1-start1 > attr(d, "units") [1] "mins"> print(d); > v <- unlist(strsplit(as.character(d), split=" ")); print(v) > Time difference of 3.189143 mins > [1] "3.18914334774017" > > > Thank you in advance for your kind help. > > C.S.David Winsemius, MD West Hartford, CT
Maybe Matching Threads
- ?to calculate sth for groups defined between points in one variable (string), / value separating/ spliting variable into groups by i.e. between start, NA, NA, stop1, start2, NA, stop2
- Extract subsets of different and unknown lengths from huge dataset
- Lattice plot
- [LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?
- [LLVMdev] Can simplifycfg kill llvm.lifetime intrinsics?