[R] Errors using large numbers ((i) all entries of 'x' must be nonnegative and finite and (ii) NAs introduced by coercion)

arun smartpink111 at yahoo.com
Tue Jul 16 19:38:28 CEST 2013



HI,
?as.integer() #documentation
Note that current implementations of R use 32-bit integers for
     integer vectors, so the range of representable integers is
     restricted to about +/-2*10^9: ‘double’s can hold much larger
     integers exactly.
as.numeric(c(75533, 4756922556, 88210, 6715122129))
#[1]      75533 4756922556      88210 6715122129
#or
 as.double(c(75533, 4756922556, 88210, 6715122129))
#[1]      75533 4756922556      88210 6715122129
A.K.





----- Original Message -----
From: PIKAL Petr <petr.pikal at precheza.cz>
To: jgibbons1 <jgibbons at hsph.harvard.edu>; "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Tuesday, July 16, 2013 12:54 PM
Subject: Re: [R] Errors using large numbers ((i) all entries of 'x' must be nonnegative and finite and (ii) NAs introduced by coercion)

Well,

You could find it yourself,

as.integer(c(75533, 4756922556, 88210, 6715122129))
[1] 75533    NA 88210    NA
Warning message:
NAs introduced by coercion 
> matrix(c(75533, 4756922556, 88210, 6715122129), nrow=2)
           [,1]       [,2]
[1,]      75533      88210
[2,] 4756922556 6715122129

Using as.integer inputs NA as integer type has limited size.

Petr


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of jgibbons1
> Sent: Tuesday, July 16, 2013 4:44 PM
> To: r-help at r-project.org
> Subject: [R] Errors using large numbers ((i) all entries of 'x' must be
> nonnegative and finite and (ii) NAs introduced by coercion)
> 
> Hello,
> I am fairly new to R, 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:
> 
> 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
> 
> 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 as such:
> 
>      > data=read.table("My.File", header=FALSE)
> 
> And I am looping through each row to perform a test like this:
> 
>      > 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])
>      + }
> 
> Here is the Error I am Getting:
> 
> 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
> 
> 
> 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!
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Errors-
> using-large-numbers-i-all-entries-of-x-must-be-nonnegative-and-finite-
> and-ii-NAs-introduced-b-tp4671685.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.

______________________________________________
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.




More information about the R-help mailing list