[R] How to perform a grouped shapiro wilk test on dataframe

arun smartpink111 at yahoo.com
Fri Apr 5 20:34:44 CEST 2013

Try this:
dat1<- read.csv("sample.csv",sep="\t",stringsAsFactors=FALSE)
 with(dat1,tapply(COUNTS,list(ACTIVITY),function(x) if (length(unique(x))==1) NA else shapiro.test(x)))
#[1] NA


#    Shapiro-Wilk normality test

#data:  x
#W = 0.4588, p-value = 8.025e-11

    Shapiro-Wilk normality test
#data:  x
#W = 0.7283, p-value = 3.76e-07
ddply(dat1,.(ACTIVITY), summarise, Pval=if(length(unique(COUNTS))==1) NA else shapiro.test(COUNTS)$p.value)
#   ACTIVITY         Pval
#1 activity1           NA
#2 activity2 8.025059e-11
#3 activity3 3.760396e-07


----- Original Message -----
From: ramoss <ramine.mossadegh at finra.org>
To: r-help at r-project.org
Sent: Friday, April 5, 2013 10:50 AM
Subject: [R] How to perform a grouped shapiro wilk test on dataframe


I was wandering if it is possible to perform on a dataframe called 'all' a
shapiro wilk normality test for COUNTS by variable Group

ACTIVITY?  Could it be done using plyer?  I saw an eg that applies to an
array but not to a dataframe:


Any thoughts would be much appreciated.

My dataframe is in shape:

1/1/13   XXXX      43
1/31/13 XXXX    60
1/1/13   YYYY     40
1/31/13 YYYY  10
etc  going for 3 months.

View this message in context: http://r.789695.n4.nabble.com/How-to-perform-a-grouped-shapiro-wilk-test-on-dataframe-tp4663438.html
Sent from the R help mailing list archive at Nabble.com.

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list