有时读取数字元素scan
并根据它们的顺序将它们配置为矩阵很有用。
> inp <- scan(text="20.79 194.5 23.89 200.9 28.49 209.5
+ 20.79 194.3 23.99 201.1 27.76 208.6
+ 22.40 197.9 24.02 201.4 29.04 210.7
+ 22.67 198.4 24.01 201.3 29.88 211.9
+ 23.15 199.4 25.14 203.6 30.06 212.2
+ 23.35 199.9 26.57 204.6")
Read 34 items
> M.in <- matrix(inp, ncol=2, byrow=TRUE)
> M.in
[,1] [,2]
[1,] 20.79 194.5
[2,] 23.89 200.9
[3,] 28.49 209.5
[4,] 20.79 194.3
[5,] 23.99 201.1
[6,] 27.76 208.6
[7,] 22.40 197.9
[8,] 24.02 201.4
[9,] 29.04 210.7
[10,] 22.67 198.4
[11,] 24.01 201.3
[12,] 29.88 211.9
[13,] 23.15 199.4
[14,] 25.14 203.6
[15,] 30.06 212.2
[16,] 23.35 199.9
[17,] 26.57 204.6
现在你可以这样做:
> t.test(M.in[,1], M.in[,2])
Welch Two Sample t-test
data: M.in[, 1] and M.in[, 2]
t = -112.7824, df = 24.18, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-181.1483 -174.6400
sample estimates:
mean of x mean of y
25.05882 202.95294
您可以用来as.data.frame
转换M.in
为数据框。)如果您确信这些被分成六个一组,您可以使用以下方法访问它们:
first6 <- M.in[ 1:6, ]