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

Chuck Cleland ccleland at optonline.net
Sun Jul 1 11:53:03 CEST 2007


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



More information about the R-help mailing list