#One Sample Z Test Ztest = function(mean,mu,sd,length){ Z = (mean-mu)/(sd/sqrt(length)) twotailpvalue = 1-2*pnorm(-abs(Z)) righttailpvalue = 1-pnorm(Z) lefttailpvalue = pnorm(Z) return(c(Z,twotailpvalue,righttailpvalue,lefttailpvalue))} Ztest(29,15,19,16)

#Two Sample Z Test Ztest2 = function(mean1,mean2,sd1,sd2,length1,length2){ Z2 = (mean1-mean2)/sqrt((sd12/length1)+(sd22/length2)) twotailpvalue = 1-2*pnorm(-abs(-Z2)) righttailpvalue = 1-pnorm(Z2) lefttailpvalue = pnorm(Z2) return(c(Z2,twotailpvalue,righttailpvalue,lefttailpvalue))} Ztest2(29,17,20,23,18,11)