[R] Missing data (Na) and chi-square tests

David Winsemius dwinsemius at comcast.net
Fri Oct 5 17:38:37 CEST 2012

On Oct 5, 2012, at 6:26 AM, Rerda wrote:

> Dear everyone
> I am a bit of a computer imbecile and are having problems with R.
> I am using R in my research project to do chi-square tests on data imported
> from excel .
> However I have som missing data in one of my variables (columns) and I need
> R to "exclude" these and make chi-square test on the data that I have.
> I use a formula to make 2x2 tables which is:
> data <- matrix(c(sum(!Variable[Group....==1]), sum(Variable[DAAC....==1]),
> sum(!Variable[Group....==0]), sum(Variable[DAAC....==0])),2,2)

This might be as simple as:

with(Variable, table( Grp.1= Group == 1, DAAC.1= DAAC == 1) )

table will produce an object that inherits from matrix and the counts of logical values will get cross tabulated. The NA values will neither be equal to 1 nor not-equal to 1, but will rather be ...NA. So they will not appear in the counts. This, of course, depends on my guess regarding you data structure being correct and my guess regarding you goals also beingcorrect. Neither of those critical bits of information have yet been offered.

> How can I get R to ignore Na's in this formula?
> Many Regards
> --
> View this message in context: http://r.789695.n4.nabble.com/Missing-data-Na-and-chi-square-tests-tp4645167.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> R-help at r-project.org 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.

David Winsemius, MD
Alameda, CA, USA

More information about the R-help mailing list