I have been struggling to figure out how to fix this error, and I thought why not try the seqanswers community. I am fairly new to R though, so please forgive me if this is a fairly easy solution.

I am trying to perform multiple Fisher's Exact tests or Pearson's Chi-squared contingency tests from a datamatrix in which data from each row is data for an independent test.

My data is formatted as such:

Where the 1st column is the identifier, the 2nd column = observations 1, the 3rd column = background counts 1, the 4th column = observations 2 and the 5th column = background counts 2.

I am loading my data like this:

And I am looping through each row to perform a test like this:

Here is the Error I am Getting:

When I replace the large number in the 3rd and 5th column with smaller numbers, the statistical calculation works fine.

Any ideas? Any help would be GREATLY appreciated!

I am trying to perform multiple Fisher's Exact tests or Pearson's Chi-squared contingency tests from a datamatrix in which data from each row is data for an independent test.

My data is formatted as such:

AAA 75533 4756922556 88210 6715122129

BBB 14869 4756983220 16384 6715193955

CCC 7230 4756990859 8559 6715201780

DDD 18332 4756979757 23336 6715187003

EEE 14733 4756983356 16826 6715193513

FFF 2918 4756995171 3433 6715206906

GGG 3726 4756994363 4038 6715206301

HHH 6196 4756991893 7011 6715203328

III 7925 4756990164 9130 6715201209

JJJ 1434 4756996655 1602 6715208737

BBB 14869 4756983220 16384 6715193955

CCC 7230 4756990859 8559 6715201780

DDD 18332 4756979757 23336 6715187003

EEE 14733 4756983356 16826 6715193513

FFF 2918 4756995171 3433 6715206906

GGG 3726 4756994363 4038 6715206301

HHH 6196 4756991893 7011 6715203328

III 7925 4756990164 9130 6715201209

JJJ 1434 4756996655 1602 6715208737

I am loading my data like this:

> data=read.table("My.File", header=FALSE)

> pvalues=c("pvalue")

> for(i in 1:10){

+ datamatrix=matrix(c(as.integer(data[i,2:5])),nrow=2)

+ fisherresult=fisher.test(datamatrix)

+ pvalues=cbind(pvalues,fisherresult[1])

+ }

> for(i in 1:10){

+ datamatrix=matrix(c(as.integer(data[i,2:5])),nrow=2)

+ fisherresult=fisher.test(datamatrix)

+ pvalues=cbind(pvalues,fisherresult[1])

+ }

Error in fisher.test(datamatrix) :

all entries of 'x' must be nonnegative and finite

In addition: Warning messages:

1: In matrix(c(as.integer(data[i, 2:5])), nrow = 2) :

NAs introduced by coercion

2: In matrix(c(as.integer(data[i, 2:5])), nrow = 2) :

NAs introduced by coercion

all entries of 'x' must be nonnegative and finite

In addition: Warning messages:

1: In matrix(c(as.integer(data[i, 2:5])), nrow = 2) :

NAs introduced by coercion

2: In matrix(c(as.integer(data[i, 2:5])), nrow = 2) :

NAs introduced by coercion

Any ideas? Any help would be GREATLY appreciated!

## Comment