[R] Help with time in R

jim holtman jholtman at gmail.com
Tue Jul 20 14:01:12 CEST 2010


> # depends on what you want to do with it.
> # if you just want to convert to seconds, use the following
> x <- c('12:23.45', '34:15.1', '1:34.23')
> # split by the ":"
> x.s <- strsplit(x, ":")
> # convert
> x.c <- sapply(x.s, function(a){
+     as.numeric(a[1]) * 60 + as.numeric(a[2])
+ })
>
>
> x.c
[1]  743.45 2055.10   94.23
>


On Tue, Jul 20, 2010 at 7:33 AM, Sarah Chisholm
<sarah.chisholm.09 at ucl.ac.uk> wrote:
> Hi,
>
> I have a problem with the time formatting in R. I have entered time in the format "MM:SS.xyz" and R has automatically classified this as a factor, but I need it numerically. However when I use as.numeric() it gives me totally different numbers. Is there any way I can tell R to read thes input as a number?
>
> Thank you very much
>
>        [[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?



More information about the R-help mailing list