如何在R中按组应用shapiro测试? [英] How to apply a shapiro test by groups in R?

查看:74
本文介绍了如何在R中按组应用shapiro测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,其中所有90个变量都具有整数数据,其类型为:

I have a dataframe where all my 90 variables have integer data, of the type:


code |变量1 | variable2 | variable3 | ...

code | variable1 | variable2 | variable3 | ...

AB | 2 | 3 | 10 | ...

AB | 2 | 3 | 10 | ...

AH | 4 | 6 | 8 | ...

AH | 4 | 6 | 8 | ...

BC | 1 | 5 | 9 | ...

BC | 1 | 5 | 9 | ...

... | ... | ... | ...

... | ... | ... | ...

我想通过变量对我的数据框应用shapiro测试(shapiro.test {stats})并写入结果在这样的表中:

I want to apply a shapiro test (shapiro.test {stats}) to my dataframe by variable and write the results in a table like:


variable_name | W | p值

variable_name | W | p-value

有人知道吗?

推荐答案

使用R中的mtcar数据

Using mtcars data from R

mydata<-mtcars
 kk<-Map(function(x)cbind(shapiro.test(x)$statistic,shapiro.test(x)$p.value),mydata)
library(plyr)
myout<-ldply(kk)
names(myout)<-c("var","W","p.value")
myout
    var         W      p.value
1   mpg 0.9475648 1.228816e-01
2   cyl 0.7533102 6.058378e-06
3  disp 0.9200127 2.080660e-02
4    hp 0.9334191 4.880736e-02
5  drat 0.9458838 1.100604e-01
6    wt 0.9432578 9.265551e-02
7  qsec 0.9732511 5.935208e-01
8    vs 0.6322636 9.737384e-08
9    am 0.6250744 7.836356e-08
10 gear 0.7727857 1.306847e-05
11 carb 0.8510972 4.382401e-04

这篇关于如何在R中按组应用shapiro测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆