R 中数据帧的正态性检验

Normality tests for dataframes in R

我正在对两个数据帧的两列进行一些正态性测试:

# Normality tests

shapiro.test(male$height)
shapiro.test(female$height)

ad.test(male$height)
ad.test(female$height)

cvm.test(male$height)
cvm.test(female$height)

lillie.test(male$height)
lillie.test(female$height)

pearson.test(male$height)
pearson.test(female$height)

sf.test(male$height)
sf.test(female$height)

但这对我来说看起来效率很低。我尝试使用 tapply 和 apply 函数,但无法正常工作。猜猜看?

你可以试试 lapply:

lapply(list(male, female), function(x) {

 list(shapiro.test(x$height),
      ad.test(x$height),
      cvm.test(x$height),
      lillie.test(x$height),
      pearson.test(x$height),
      sf.test(x$height))

})