2012-11-24 3 views
0

t.test의 결과를 파일로 작성하려면 어떻게해야합니까?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' 
+5

'? capture.output' – Dason

+1

capture.output (t.test (X), 파일 = "테스트") –

답변

5
> sink("out.txt") 
> x <- scan() 
1: 12.2 10.8 12.0 11.8 11.9 12.4 11.3 12.2 12.0 12.3 
11: 
Read 10 items 
> t.test(x) 
> sink() 
> readLines("out.txt") 
[1] ""              
[2] "\tOne Sample t-test"         
[3] ""              
[4] "data: x "           
[5] "t = 76.2395, df = 9, p-value = 5.814e-14"    
[6] "alternative hypothesis: true mean is not equal to 0 " 
[7] "95 percent confidence interval:"      
[8] " 11.5372 12.2428 "         
[9] "sample estimates:"         
[10] "mean of x "           
[11] " 11.89 "           
[12] ""    
관련 문제