[R] How to avoid rounding of matrix elements?

Liaw, Andy andy_liaw at merck.com
Fri Jan 7 02:38:06 CET 2005


Use the digits option to print():

> print(mdat, digits=20)
                      [,1]        [,2]               [,3]        [,4]
[1,] 0.0187972949999999990 1.000000000 0.0105002420000000 0.074216423
[2,] 0.4446208549999999800 0.000320438 1.1087556380000001 0.036289824

The output may look rounded, but they're not.

Andy

> From: Ulas Karaoz
> 
> Hi all R-users,
> If I have a matrix with numeric elements as follows, the values are 
> rounded when I try to refer to a specifici element using [], 
> the value 
> is rounded.
> The same thing happens if the matrix is read from a file, the 
> values are 
> stored to the correct precision but then when I try to refer to a 
> specific element (such as using [], it is rounded.
> 
> How do I avoid this rounding?
>  
> >mdat<-matrix(c(0.0187972950,0.4446208550,1.0000000000,0.00032
> 04380,0.0105002420,1.1087556380,0.0742164230,0.0362898240), 
> nrow = 2, ncol=4)
>  > mdat
>            [,1]        [,2]       [,3]       [,4]
> [1,] 0.01879729 1.000000000 0.01050024 0.07421642
> [2,] 0.44462085 0.000320438 1.10875564 0.03628982
> 
> Thanks.
> 
> ______________________________________________
> 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
> 
>




More information about the R-help mailing list