rm(list = ls())
Sample data
head(ToothGrowth)
## len supp dose
## 1 4.2 VC 0.5
## 2 11.5 VC 0.5
## 3 7.3 VC 0.5
## 4 5.8 VC 0.5
## 5 6.4 VC 0.5
## 6 10.0 VC 0.5
Version 1: Testing each subset
## Subset data
x <- subset(ToothGrowth,supp=="VC" & dose==0.5)
## Test data
p <- shapiro.test(x$len)
p
##
## Shapiro-Wilk normality test
##
## data: x$len
## W = 0.89, p-value = 0.1696
Version 2: Test grouped data
library(rstatix)
p <- ToothGrowth %>% group_by(supp,dose) %>% shapiro_test(len)
p
## # A tibble: 6 x 5
## supp dose variable statistic p
## <fct> <dbl> <chr> <dbl> <dbl>
## 1 OJ 0.5 len 0.893 0.182
## 2 OJ 1 len 0.927 0.415
## 3 OJ 2 len 0.963 0.815
## 4 VC 0.5 len 0.890 0.170
## 5 VC 1 len 0.908 0.270
## 6 VC 2 len 0.973 0.919