I cannot find the solutions in the mannual about "import and export of data". For example, I run>chisq.test(x,p=probs)chi-squared..... ......... How can I write the output into a file? Is there some file operations in R? Actually, I only want to save the P-value. But I don''t know how I can extract the P-value field only from the output of chisq.test. So, I think I would better save all the output. I tried cat/write....They cannot do this. Thanks in advance. [[alternate HTML version deleted]]
Ko-Kang Kevin Wang
2003-Mar-26 01:12 UTC
[R] How to write the output of a function into a file?
Hi, On Tue, 25 Mar 2003, yanni at cec wrote:> Date: Tue, 25 Mar 2003 17:58:33 -0600 > From: "yanni at cec" <ys3 at cec.wustl.edu> > To: r-help at stat.math.ethz.ch > Subject: [R] How to write the output of a function into a file? > > I cannot find the solutions in the mannual about "import and export of data". > For example, I run > >chisq.test(x,p=probs) > chi-squared..... > > ......... > > How can I write the output into a file? Is there some file operations in R?Take a look at ?write ?save> Actually, I only want to save the P-value. But I don't know how I can extract the P-value field only from the output > of chisq.test. So, I think I would better save all the output. I tried cat/write....They cannot do this.It is very clearly documented in ?chisq.test (to get only the p-value). -- Cheers, Kevin ------------------------------------------------------------------------------ /* Time is the greatest teacher, unfortunately it kills its students */ -- Ko-Kang Kevin Wang Master of Science (MSc) Student SLC Tutor and Lab Demonstrator Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 Ph: 373-7599 x88475 (City) x88480 (Tamaki)
Gavin Simpson
2003-Mar-26 09:19 UTC
[R] How to write the output of a function into a file?
does sink() do what you want? see ?sink for more> #divert printed results to file > sink(file = output.txt) > #commands here > chisq.test(x,p=probs) > #turn off sink > sink(file = NULL)If you are not typing the commands at the prompt but are using an external editor or text file for your commands via source() then you need to wrap chisq.test(x,p=probs) in print() eg: print(chisq.test(x,p=probs)) Hope this helps Gavin %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpson at ucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of yanni at cec Sent: 25 March 2003 23:59 To: r-help Subject: [R] How to write the output of a function into a file? I cannot find the solutions in the mannual about "import and export of data". For example, I run>chisq.test(x,p=probs)chi-squared..... ......... How can I write the output into a file? Is there some file operations in R? Actually, I only want to save the P-value. But I don't know how I can extract the P-value field only from the output of chisq.test. So, I think I would better save all the output. I tried cat/write....They cannot do this. Thanks in advance. [[alternate HTML version deleted]] ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help