[R] Single Precision (4 byte) floats with readBin

Peter Lauren peterdlauren at yahoo.com
Wed Sep 27 22:11:10 CEST 2006


I would like to use readBin to read a binary data
file.  Most of the data is 4-byte floating point but,
for some reason, only double precision appears to be
offered.  I tried 
fVariable=readBin(iFile,what=single());
and got 35.87879 which looks believable except that
the correct value is 3.030303.  I then tried
fVariable=readBin(iFile,what=single(),4);
and got 
[1]  3.831111e+10  6.657199e+10 -5.592394e+29
-5.592397e+29

For the second call, there were two more single
precision floats of value 3.030303 followed by two
more with values 40.46 and 0.00 respectively.

Is there any way around this problem other than to
make the input data double (which I definitely do not
want to do)? 

Many thanks in advance,
Peter.



More information about the R-help mailing list