Re: [R] How to z-standardize for subgroups?

2009-11-29 Thread Karsten Wolf
Hi Jorge, Chuck and Kane, thanks for your input! The following code based on Jorge's answer did the trick to standardize for subgroups within multiple columns: # define a standardize function, but you could also define your custom standardize function here z.mean.sd <- function(data){ retu

Re: [R] How to z-standardize for subgroups?

2009-11-29 Thread Chuck Cleland
N = 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 > --- On Sun, 11/29/09, Karsten Wolf wrote: > >> From: Karsten Wolf >> Subjec

Re: [R] How to z-standardize for subgroups?

2009-11-29 Thread John Kane
http://finzi.psych.upenn.edu/R/library/QuantPsyc/html/Make.Z.html Make.Z in the QuantPsych package may already do it. --- On Sun, 11/29/09, Karsten Wolf wrote: > From: Karsten Wolf > Subject: [R] How to z-standardize for subgroups? > To: r-help@r-project.org > Received: Sunday,

Re: [R] How to z-standardize for subgroups?

2009-11-29 Thread Jorge Ivan Velez
Hi Karsten, Let me assume your data is called d. If I understood what you are trying to do, the following might help: res <- apply(d, 2, tapply, d$group, scale) res See ?apply, ?tapply and ?scale for more information. HTH, Jorge On Sun, Nov 29, 2009 at 10:41 AM, Karsten Wolf <> wrote: > Hi f

[R] How to z-standardize for subgroups?

2009-11-29 Thread Karsten Wolf
Hi folks, I have a dataframe df.vars with the follwing structure: var1 var2 var3 group Group is a factor. Now I want to standardize the vars 1-3 (actually - there are many more) by class, so I define z.mean.sd <- function(data){ return.values <- (data - mean(data)) / (sd(dat