[R] How to perform a grouped shapiro wilk test on dataframe
arun
smartpink111 at yahoo.com
Fri Apr 5 20:34:44 CEST 2013
Hi,
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)))
#$activity1
#[1] NA
#$activity2
# Shapiro-Wilk normality test
#data: x
#W = 0.4588, p-value = 8.025e-11
#
#$activity3
#
Shapiro-Wilk normality test
#
#data: x
#W = 0.7283, p-value = 3.76e-07
library(plyr)
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
A.K.
----- Original Message -----
From: ramoss <ramine.mossadegh at finra.org>
To: r-help at r-project.org
Cc:
Sent: Friday, April 5, 2013 10:50 AM
Subject: [R] How to perform a grouped shapiro wilk test on dataframe
Hello,
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:
lapply(split(dataset1$Height,dataset1$Group),shapiro.test)
Any thoughts would be much appreciated.
My dataframe is in shape:
dat ACTIVIT COUNTS
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
https://stat.ethz.ch/mailman/listinfo/r-help
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