diferencia de medias

difmedias<-function(x,y,z){
   m1=mean(x)
   m2=mean(y)
   n1=length(x)
   n2=length(y)
   v=(((var(x)/n1)+(var(y)/n2))^2)/((((var(x)/n1)^2)/(n1-1))+(((var(y)/n2)^2)/(n2 -1)))
error=qt(z,v,lower.tail=TRUE)*(sqrt(var(x)/length(x)+var(y)/length(y)))
cat('[',(m1-m2)-error,',',(m1-m2)+error,']')
}
x<-c(182,170,175,167,171,174,181,169,174,   174,    170,    176,    168,    178,    180)
y<-c(181,173,177,170,170,175,   169,    169,    171,    173,    177,    182,    179,    165,    174)
difmedias(x,y,0.975)
[ -3.337921 , 3.871255 ]
t.test(x,y,alternative='two.sided',var.equal=FALSE)

    Welch Two Sample t-test

data:  x and y
t = 0.15154, df = 27.995, p-value = 0.8806
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -3.337921  3.871255
sample estimates:
mean of x mean of y 
 173.9333  173.6667