How to apply a shapiro test by groups in R?

后端 未结 3 1912
萌比男神i
萌比男神i 2021-01-24 10:27

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

code | variable1 | variable2 | variable3 | ...

AB | 2 | 3 | 10 |

3条回答
  •  春和景丽
    2021-01-24 10:34

    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
    

提交回复
热议问题