[R] storage and single-precision

Duncan Murdoch murdoch.duncan at gmail.com
Thu Sep 8 18:33:33 CEST 2011


On 08/09/2011 11:14 AM, Mike Miller wrote:
> On Thu, 8 Sep 2011, Duncan Murdoch wrote:
>
> >  On 11-09-07 6:25 PM, Mike Miller wrote:
> >
> >>  I'm getting the impression from on-line docs that R cannot work with
> >>  single-precision floating-point numbers, but that it has a pseudo-mode
> >>  for single precision for communication with external programs.
> >>
> >>  I don't mind that R is using doubles internally, but what about
> >>  storage? If all I need to store is single-precision (32-bit), can I do
> >>  that?  When it is read back into R it can be converted from single to
> >>  double (back to 64-bit).
> >>
> >>  Furthermore, the data are numbers from 0.000 to 2.000 with no missing
> >>  values that could be stored just as accurately as unsigned 16-bit
> >>  integers from 0 to 2000.  That would be the best plan for me.
> >
> >
> >  writeBin is quite flexible in converting between formats if you just
> >  want to store them on disk.  To use nonstandard formats in memory will
> >  require external support; it's not easy.
>
>
> Thanks.  I can see now that writeBin will store unsigned 16-bit integers,
> which is what I want.  There is one other issue -- with save() I'm allowed
> to use compression (e.g., gzip), but there doesn't seem to be a
> compression option in writeBin.  Is there a way to get the best of both
> worlds?  The data are highly nonrandom and at most 11 bits will be used
> per integer, so the compression ratio should be pretty good, if I can have
> one.

There are various compressed connections (gzfile etc).

Duncan Murdoch



More information about the R-help mailing list