R 如何将t.test的结果写入文件?
如何将R 如何将t.test的结果写入文件?,r,R,如何将t.test的结果写入文件 > x [1] 12.2 10.8 12.0 11.8 11.9 12.4 11.3 12.2 12.0 12.3 > t.test(x) One Sample t-test data: x t = 76.2395, df = 9, p-value = 5.814e-14 alternative hypothesis: true mean is not equal to 0 95 percent confidence
t.test
的结果写入文件
> x
[1] 12.2 10.8 12.0 11.8 11.9 12.4 11.3 12.2 12.0 12.3
> t.test(x)
One Sample t-test
data: x
t = 76.2395, df = 9, p-value = 5.814e-14
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
11.5372 12.2428
sample estimates:
mean of x
11.89
> write(t.test(x),file="test")
Error in cat(list(...), file, sep, fill, labels, append) :
argument 1 (type 'list') cannot be handled by 'cat'
>接收器(“out.txt”)
>x t检验(x)
>水槽()
>readLines(“out.txt”)
[1] ""
[2] “\t样本t检验”
[3] ""
[4] “数据:x”
[5] “t=76.2395,df=9,p值=5.814e-14”
[6] “替代假设:真实平均值不等于0”
[7] “95%置信区间:”
[8] " 11.5372 12.2428 "
[9] “样本估计值:”
[10] “x的平均值”
[11] " 11.89 "
[12] ""
>接收器(“out.txt”)
>x t检验(x)
>水槽()
>readLines(“out.txt”)
[1] ""
[2] “\t样本t检验”
[3] ""
[4] “数据:x”
[5] “t=76.2395,df=9,p值=5.814e-14”
[6] “替代假设:真实平均值不等于0”
[7] “95%置信区间:”
[8] " 11.5372 12.2428 "
[9] “样本估计值:”
[10] “x的平均值”
[11] " 11.89 "
[12] ""
这篇文章发表后,扫帚
软件包发布了。它使处理模型输出变得越来越好。特别是,函数tidy()
将把模型输出转换为数据帧,以便进一步处理
x <- c(12.2, 10.8, 12.0, 11.8, 11.9, 12.4, 11.3, 12.2, 12.0, 12.3)
t_test <- t.test(x)
library(broom)
tidy_t_test <- broom::tidy(t_test)
tidy_t_test
#> # A tibble: 1 x 8
#> estimate statistic p.value parameter conf.low conf.high method
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 11.9 76.2 5.81e-14 9 11.5 12.2 One S…
#> # … with 1 more variable: alternative <chr>
write.csv(tidy_t_test, "out.csv")
x
#>1 11.9 76.2 5.81e-14 9 11.5 12.2一个S…
#>#…还有一个变量:可选
write.csv(整洁测试,“out.csv”)
这篇文章发表后,扫帚
软件包发布了。它使处理模型输出变得越来越好。特别是,函数tidy()
将把模型输出转换为数据帧,以便进一步处理
x <- c(12.2, 10.8, 12.0, 11.8, 11.9, 12.4, 11.3, 12.2, 12.0, 12.3)
t_test <- t.test(x)
library(broom)
tidy_t_test <- broom::tidy(t_test)
tidy_t_test
#> # A tibble: 1 x 8
#> estimate statistic p.value parameter conf.low conf.high method
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 11.9 76.2 5.81e-14 9 11.5 12.2 One S…
#> # … with 1 more variable: alternative <chr>
write.csv(tidy_t_test, "out.csv")
x
#>1 11.9 76.2 5.81e-14 9 11.5 12.2一个S…
#>#…还有一个变量:可选
write.csv(整洁测试,“out.csv”)
capture.output(t.test(x),file=“test”)capture.output(t.test(x),file=“test”)非常感谢您的指针。但是,功能tidy在broom包中不可用。我猜你是从Cran的网站信息中得到的,这段代码对我很有用,谢谢你的指点。但是,功能tidy在broom包中不可用。我猜你是从Cran的网站信息中得到的这段代码对我有用