[R] How to run Shapiro-Wilk test for each grouped variable?

Iurie Malai iurie.malai at gmail.com
Fri Apr 9 14:16:25 CEST 2010

I want to run Shapiro-Wilk test for each variable in my dataset, each
grouped by variable groupFactor.
I have these working commands:

> data.n<-names(data) # put names into a vector called data.n
> by(eval(parse(text=(paste("data",data.n[3],sep="$")))), data$factor, shapiro.test) #run shapiro.test

but I must to change the variable number manualy. How to automate this?

I tried this:

> for (r in 3:18) {
> by(eval(parse(text=(paste("data",data.n[3],sep="$")))), data$groupFactor, shapiro.test)
> }

but not working and no errors. Why?

Please help.

Iurie Malai, Senior Lecturer
Department of Psychology
Faculty of Psychology and Special Education
Ion Creanga Moldova Pedagogical State University - www.upsm.md

More information about the R-help mailing list