[R] Convert string to time

Phillip Stich phillip.stich at gmail.com
Mon Apr 13 19:10:08 CEST 2009


On 12 April 2009 at 21:00, Peter Kraglund Jacobsen wrote:
> One variable contains values (1.30 - one hour and thirty minutes, 1.2
> (which is supposed to be 1.20 - one hour and twenty minutes)). I would
> like to convert to a minute variable so 1.2 is converted to 80
> minutes. How?

You could make a simple little function that does the following

timeconv <- function(time){
    newtime <- floor(time)*60 + (time-floor(time))*100
    return(newtime)
}

> floor(1.2)*60 + (1.2-floor(1.2))*100
[1] 80
> floor(1.4)*60 + (1.4-floor(1.4))*100
[1] 100
> floor(1.3)*60 + (1.3-floor(1.3))*100
[1] 90

Phil

| ______________________________________________
| 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.




More information about the R-help mailing list