Skip to content
Prev 202062 / 398503 Next

How to z-standardize for subgroups?

On 11/29/2009 4:23 PM, John Kane wrote:
For a single variable, you could use ave() and scale() together like this:

with(iris, ave(Sepal.Width, Species, FUN = scale))

  To scale more than one variable in a concise call, consider something
along these lines:

apply(iris[,1:4], 2, function(x){ave(x, iris$Species, FUN = scale)})

hope this helps,

Chuck Cleland