removeGroupMeans <- function(values, groupsID, weights = 1) {
names(values) <- groupsID
gmeans <- by(cbind(values, weights), groupsID, function(x) weighted.mean(x[,1], x[,2], na.rm=TRUE))
values - gmeans[as.character(groupsID)]
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.