Try this also: x$x - ave(x$x, x$f)
On Thu, Nov 18, 2010 at 12:02 PM, Lancaster, Anthony < anthony_lancas...@brown.edu> wrote: > Hi, > I'd appreciate help with this. I have a data matrix with one column, called > f in the example below, a factor. I'd like to subtract the means from each > of > other columns for each level of the factor. That is, in the example, to go > from the first matrix below to the second. I know SWEEP will take out > means, > but I want to do this for each level of the factor. > f x > 1 2 > 1 0 > 2 0 > 2 4 > 2 2 > > f xnew > 1 1 > 1 -1 > 2 -2 > 2 2 > 2 0 > Thanks > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ 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.