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

Ivan Calandra ivan.calandra at uni-hamburg.de
Fri Apr 9 15:39:38 CEST 2010


Maybe you should change the "3" in the loop with "r" like:
for (r in 3:18) {
data$groupFactor, shapiro.test)

I think it should work, if not, I have already a similar script for that.

Le 4/9/2010 15:17, David Winsemius a écrit :
> On Apr 9, 2010, at 8:16 AM, Iurie Malai wrote:
>> 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)
>>> }
> Not able to test since you have provided code that works with data 
> that is not available. Inside for loops one needs either to make an 
> assignment or print the results. Had the data been available I would 
> have wrapped print() around the full by expression to see if my 
> hypothesis could be tested.

PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de


More information about the R-help mailing list