Hello R-Helpers! I have a vector of times of events that time is fraction of 1, because it was calculated in excel. Are there some way to format a period greater than 24h in a format like excel [h]:mm:ss? Exemple: test = c(1.424708, 0.028674)> chron (times. = test [2], format = "h:m:S")[1] 00:41:17> chron (times. = test, format = "h:m:S")Time in days: [1] 1.424708 0.028674 I need an output like: 34:11:35 0:41:17 Thanks in advanced, Raoni -- Raoni Rosa Rodrigues Research Associate of Fish Transposition Center CTPeixes Universidade Federal de Minas Gerais - UFMG Brasil rodrigues.raoni at gmail.com
Raoni, You could write your own function to do this. For example, using the period class from the R package lubridate, you could do something like this: days2 <- function(x) { h1 <- 24*x h <- floor(h1) m1 <- 60*(h1 - h) m <- floor(m1) s <- round(60*(m1 - m)) new_period(second=s, minute=m, hour=h) } library(lubridate) test <- c(1.424708, 0.028674) days2(test) [1] "34H 11M 35S" "41M 17S" Jean On Mon, Oct 26, 2015 at 1:48 PM, Cacique Samurai <caciquesamurai at gmail.com> wrote:> Hello R-Helpers! > > I have a vector of times of events that time is fraction of 1, because > it was calculated in excel. Are there some way to format a period > greater than 24h in a format like excel [h]:mm:ss? > > Exemple: > > test = c(1.424708, 0.028674) > > > chron (times. = test [2], format = "h:m:S") > [1] 00:41:17 > > > chron (times. = test, format = "h:m:S") > Time in days: > [1] 1.424708 0.028674 > > I need an output like: > > 34:11:35 0:41:17 > > Thanks in advanced, > > Raoni > > -- > Raoni Rosa Rodrigues > Research Associate of Fish Transposition Center CTPeixes > Universidade Federal de Minas Gerais - UFMG > Brasil > rodrigues.raoni at gmail.com > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >[[alternative HTML version deleted]]
Hello Jean! Thanks very much for your help and assistence! Works very fine! All best, Raoni 2015-10-26 17:02 GMT-02:00 Adams, Jean <jvadams at usgs.gov>:> Raoni, > > You could write your own function to do this. For example, using the period > class from the R package lubridate, you could do something like this: > > days2 <- function(x) { > h1 <- 24*x > h <- floor(h1) > m1 <- 60*(h1 - h) > m <- floor(m1) > s <- round(60*(m1 - m)) > new_period(second=s, minute=m, hour=h) > } > > library(lubridate) > test <- c(1.424708, 0.028674) > days2(test) > > [1] "34H 11M 35S" "41M 17S" > > Jean > > On Mon, Oct 26, 2015 at 1:48 PM, Cacique Samurai <caciquesamurai at gmail.com> > wrote: >> >> Hello R-Helpers! >> >> I have a vector of times of events that time is fraction of 1, because >> it was calculated in excel. Are there some way to format a period >> greater than 24h in a format like excel [h]:mm:ss? >> >> Exemple: >> >> test = c(1.424708, 0.028674) >> >> > chron (times. = test [2], format = "h:m:S") >> [1] 00:41:17 >> >> > chron (times. = test, format = "h:m:S") >> Time in days: >> [1] 1.424708 0.028674 >> >> I need an output like: >> >> 34:11:35 0:41:17 >> >> Thanks in advanced, >> >> Raoni >> >> -- >> Raoni Rosa Rodrigues >> Research Associate of Fish Transposition Center CTPeixes >> Universidade Federal de Minas Gerais - UFMG >> Brasil >> rodrigues.raoni at gmail.com >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. > >-- Raoni Rosa Rodrigues Research Associate of Fish Transposition Center CTPeixes Universidade Federal de Minas Gerais - UFMG Brasil rodrigues.raoni at gmail.com