if (require(tidyr)) {
Sleep2 <- sleep |> spread( key=group, val=extra )
names(Sleep2) <- c("subject", "drug1", "drug2")
swap(Sleep2, drug1 ~ drug2)
mean( ~(drug1 - drug2), data=Sleep2)
do(3) * mean( ~(drug1 - drug2), data=Sleep2 |> swap(drug1 ~ drug2) )
}
Run the code above in your browser using DataLab