方法一:tapply
with(iris,tapply(Sepal.Length, Species, shapiro.test)) #方法一
$setosa
Shapiro-Wilk normality test
data: X[[i]]
W = 0.9777, p-value = 0.4595
$versicolor
Shapiro-Wilk normality test
data: X[[i]]
W = 0.97784, p-value = 0.4647
$virginica
Shapiro-Wilk normality test
data: X[[i]]
W = 0.97118, p-value = 0.2583
方法二:with
with(iris,by(Sepal.Length, Species, shapiro.test)) #方法二
Species: setosa
Shapiro-Wilk normality test
data: dd[x, ]
W = 0.9777, p-value = 0.4595
----------------------------------------------------------
Species: versicolor
Shapiro-Wilk normality test
data: dd[x, ]
W = 0.97784, p-value = 0.4647
----------------------------------------------------------
Species: virginica
Shapiro-Wilk normality test
data: dd[x, ]
W = 0.97118, p-value = 0.2583
网友评论