带有一些虚拟数据
set.seed(1)
input1 <- rnorm(20, mean = -1)
input2 <- rnorm(20, mean = 5)
重命名或创建具有所需名称的对象会更容易:
Fruits <- input1
Vegetables <- input2
t.test(x = Fruits, y = Vegetables, paired = TRUE, alternative = "two.sided")
Paired t-test
data: Fruits and Vegetables
t = -18.6347, df = 19, p-value = 1.147e-13
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-6.454791 -5.151218
sample estimates:
mean of the differences
-5.803005
但是如果你真的想在事后这样做,那么抓住返回的对象t.test()
:
tmp <- t.test(x = input1, y = input2, paired = TRUE, alternative = "two.sided")
看对象的结构tmp
> str(tmp)
List of 9
$ statistic : Named num -18.6
..- attr(*, "names")= chr "t"
$ parameter : Named num 19
..- attr(*, "names")= chr "df"
$ p.value : num 1.15e-13
$ conf.int : atomic [1:2] -6.45 -5.15
..- attr(*, "conf.level")= num 0.95
$ estimate : Named num -5.8
..- attr(*, "names")= chr "mean of the differences"
$ null.value : Named num 0
..- attr(*, "names")= chr "difference in means"
$ alternative: chr "two.sided"
$ method : chr "Paired t-test"
$ data.name : chr "input1 and input2"
- attr(*, "class")= chr "htest"
并注意data.name
组件。我们可以用字符串替换它:
tmp$data.name <- "Fuits and Vegetables"
印刷品tmp
:
> tmp
Paired t-test
data: Fuits and Vegetables
t = -18.6347, df = 19, p-value = 1.147e-13
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-6.454791 -5.151218
sample estimates:
mean of the differences
-5.803005