x y
1 20.5 20.7
2 19.8 19.8
3 20.4 19.5
4 20.1 20.8
5 20.0 20.4
6 19.0 19.6
7 19.9 20.2
8 19.7
这是excel数据
复制到剪贴板,采用> mydata<-read.dlim("clipboard")读入mydata
> mydata<-read.delim("clipboard")
> mydata
x y
1 20.5 20.7
2 19.8 19.8
3 20.4 19.5
4 20.1 20.8
5 20.0 20.4
6 19.0 19.6
7 19.9 20.2
8 19.7 NA
进行t检验可以
> t.test(mydata[1],mydata[2],var.equal=TRUE)
Two Sample t-test
data: mydata[1] and mydata[2]
t = -0.8548, df = 13, p-value = 0.4081
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.7684249 0.3327106
sample estimates:
mean of x mean of y
19.92500 20.14286
但是进行方差分析,就不可以了。
> var.test(mydata[1],mydata[2])
Error in var.test.default(mydata[1], mydata[2]) :
not enough 'x' observations
是为什么?
但是如果采用这样的方式输入
> xx<-c(20.5,19.8,20.4,20.1,20,19,19.9,19.7)
> yy<-c(20.7,19.8,19.5,20.8,20.4,19.6,20.2)
> var.test(xx,yy)
F test to compare two variances
data: xx and yy
F = 0.7932, num df = 7, denom df = 6, p-value = 0.7608
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.1392675 4.0600387
sample estimates:
ratio of variances
0.7931937
就可以运行
这说明和read.delim()命令获得数据格式有关系,但是用excel整理数据太普遍了,这个问题,如何解决?请朋友指点。