Re: [R] Applying function to data.frame

2007-10-08 Thread Gabor Grothendieck
Your function needs to be able to work on vector input, e.g. transform( y, time=Vectorize(str_to_millis)( as.character(time) ) ) or just do this: library(chron) y$time <- 24 * 60 * 60 * 1000 * as.numeric(times(y$time)) On 10/8/07, Rees, David <[EMAIL PROTECTED]> wrote: > Hi, > > If I have the

Re: [R] Applying function to data.frame

2007-10-08 Thread jim holtman
try this: > x <- read.table(textConnection(" time val + 1 08:00:05.834 1 + 2 08:03:13.345 2 + 3 08:10:12.443 3"), header=TRUE) > z <- strsplit(as.character(x$time), ":") > newtime <- lapply(z, function(a) as.numeric(a) %*% c(360, 6, 1000)) > x$time <- unlist(newtime) > x

[R] Applying function to data.frame

2007-10-08 Thread Rees, David
Hi, If I have the following data.frame >y time val 1 08:00:05.834 1 2 08:03:13.345 2 3 08:10:12.443 3 > and the following function which converts the time string to the number of milliseconds since midnight > str_to_millis function( s ) { a <- as.numeric( unlist( strsplit(s,":