[R] How to save results from chisq.test or mantelhaen.test to file

ronggui ronggui.huang at gmail.com
Sun Jul 1 20:03:11 CEST 2007


Maybe _dput_ is another way, and you can use _dget _ to get it back.

2007/7/1, Chuck Cleland <ccleland at optonline.net>:
> adschai at optonline.net wrote:
> > Hi,
> >
> > I am new to these functions. I'm wondering if there is anyway to save the entire results (all attributes of the result object) from the chisq.test or mantelhaen.test functions? For example, from chisq.test function, you will have statistic, parameter, p.value, expected, etc. in the result list. How can I save all of them in one shot to, says, a text file or csv file? Thank you.
> >
> > - adschai
>
>   You could unlist() the result, coerce it to a data frame, then use
> write.table().  For example, something like this:
>
> write.table(as.data.frame(t(unlist(chisq.test(InsectSprays$count > 7,
> InsectSprays$spray)))), quote=FALSE)
>
> or
>
> write.table(as.data.frame(unlist(chisq.test(InsectSprays$count > 7,
> InsectSprays$spray))), quote=FALSE)
>
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Chuck Cleland, Ph.D.
> NDRI, Inc.
> 71 West 23rd Street, 8th floor
> New York, NY 10010
> tel: (212) 845-4495 (Tu, Th)
> tel: (732) 512-0171 (M, W, F)
> fax: (917) 438-0894
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Ronggui Huang
Department of Sociology
Fudan University, Shanghai, China



More information about the R-help mailing list