On Sun, Jan 16, 2011 at 5:48 AM, <bill.venab...@csiro.au> wrote: > Here is one way > > Here is one way: > >> con <- textConnection(" > + ID TIME OBS > + 001 2200 23 > + 001 2400 11 > + 001 3200 10 > + 001 4500 22 > + 003 3900 45 > + 003 5605 32 > + 005 1800 56 > + 005 1900 34 > + 005 2300 23") >> dat <- read.table(con, header = TRUE, > + colClasses = c("factor", "numeric", "numeric")) >> closeAllConnections() >> >> tmp <- lapply(split(dat, dat$ID), > + function(x) within(x, TIME <- TIME - min(TIME))) >> split(dat, dat$ID) <- tmp
Or, in one line with ddply: library(plyr) ddply(dat, "ID", transform, TIME = TIME - min(TIME)) Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ ______________________________________________ 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.