[R] Single Precision (4 byte) floats with readBin
Peter Lauren
peterdlauren at yahoo.com
Wed Sep 27 22:42:14 CEST 2006
--- Sundar Dorai-Raj <sundar.dorai-raj at pdf.com> wrote:
>
>
> Peter Lauren said the following on 9/27/2006 3:11
> PM:
> > 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.
> >
> > ______________________________________________
> > 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
> > and provide commented, minimal, self-contained,
> reproducible code.
>
>
> Hi, Peter,
>
> I believe you can use
>
> readBin(file, double(), size = 4)
>
It worked! Thanks very much.
Peter.
More information about the R-help
mailing list