1、均值是400,样本是397,面包的重量是否减少了,
读文件,方法一
breads <- read.csv("breads.csv")
读文件,方法二
breads <- read.csv(file.choose())
计算样本均值和方差
mean(breads$weight)//均值
sd(breads$weight)//方差
- date weight
2015/1/7 386.7
2015/1/8 396.7
2015/1/9 409.8
2015/1/10 384.5
2015/1/11 394.3
2015/1/12 396.2
2015/1/13 401.6
2015/1/14 392.8
2015/1/15 413.5
2015/1/16 393.7
2015/1/17 398.9
2015/1/18 404.1
2015/1/19 391.3
2015/1/20 385.3
2015/1/21 411.6
2015/1/22 373.5
2015/1/23 403.2
2015/1/24 395.3
2015/1/25 404.4
2015/1/26 399
2015/1/27 414.4
2015/1/28 383.8
2015/1/29 409.8
2015/1/30 413.2
2015/1/31 395
2015/2/1 372.2
2015/2/2 399.4
2015/2/3 389.5
2015/2/4 402.4
2015/2/5 397.7
2、画出图形
install.packages("ggplot2")
library(ggplot2)
ggplot(breads,aes(x= weight))+geom_histogram(binwidth = 10,fill = "steelblue",colour = "black",alpha = 0.5)+xlab(
+ "面包的重量")+ylab("个数")+ggtitle("面包数据的直方图")
如下图
3、t检验
t.test(breads$weight,mu = 400)
结果
One Sample t-test
data: breads$weight
t = -1.4411, df = 29, p-value = 0.1603
alternative hypothesis: true mean is not equal to 400
95 percent confidence interval:
393.0488 401.2045
sample estimates:
mean of x
397.1267
由结论知0.1603大于0.05,故不拒绝原假设。