> # Set up the ratio variables > system.time({ > temp <- cbind(data, do.call(cbind, lapply(names(data)[3:4], function(.x) > { > unlist(by(data, data$group, function(.y) .y[,.x] / > max(.y[,.x]))) > }))) > colnames(temp)[5:6] <- paste(colnames(data)[3:4], 'ind.to.max', sep = '.') > }) >
This part can be done quite straightforwardly with plyr: library(plyr) temp <- ddply(data, c("group"), transform, a.ind.to.max = a / max(a), b.ind.to.max = b / max(b)) 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.