> # 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...@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@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? ______________________________________________ R-help@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.