[R] scan seems to modify the data

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed Mar 31 23:48:41 CEST 2004



Stephane DRAY wrote:
> 
> Hello list,
> I have used scan function to import data into R. I have done some analysis
> and find strange results. I have found my problem : when importing data
> with scan, this can slightly modify the data :
> 
>  > write(c(0.251,3.399,-0.481,0.266),"essai.txt")
>  > scan("essai.txt")
> Read 4 items
> [1]  0.251  3.399 -0.481  0.266
>  > print(scan("essai.txt"),17)
> Read 4 items
> [1]  0.25100000000000000  3.39900000000000000
> -0.48099999999999998  0.26600000000000001
> 
> Is it normal ? Is it a bug ?

It is normal, that there are no exact representations for floating point
numbers in a computer (you have only a limited number of bits to
represent them!).
In this case, it is not scan(), but just the representation: Try out and
type 
  print(c(0.251,3.399,-0.481,0.266), 17)

Uwe Ligges



> thanks in advance,
> Sincerely.
> 
>  > version
>           _
> platform i386-pc-mingw32
> arch     i386
> os       mingw32
> system   i386, mingw32
> status
> major    1
> minor    8.1
> year     2003
> month    11
> day      21
> language R
> Stéphane DRAY
> --------------------------------------------------------------------------------------------------
> 
> Département des Sciences Biologiques
> Université de Montréal, C.P. 6128, succursale centre-ville
> Montréal, Québec H3C 3J7, Canada
> 
> Tel : 514 343 6111 poste 1233
> E-mail : stephane.dray at umontreal.ca
> --------------------------------------------------------------------------------------------------
> 
> Web                                          http://www.steph280.freesurf.fr/
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.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