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

From: Peter Lauren <peterdlauren_at_yahoo.com>
Date: Wed 27 Sep 2006 - 20:42:14 GMT

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



R-help@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. Received on Thu Sep 28 06:44:57 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 27 Sep 2006 - 21:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.