Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
You want to transform variables by performing operations on groups of data, as specified by a grouping variable.
Use ddply() from
the plyr package with the transform()
function, and specify the operations:
library(MASS)# For the data setlibrary(plyr)cb<-ddply(cabbages,"Cult",transform,DevWt=HeadWt-mean(HeadWt))Cult Date HeadWt VitC DevWt c39 d162.551-0.40666667c39 d162.255-0.70666667...c52 d211.566-0.78000000c52 d211.672-0.68000000