[R] Conversion to Binary (base2)
Carl Witthoft
carl at witthoft.com
Fri Sep 26 00:15:05 CEST 2008
It occurs to me that Christos' method could be made more flexible by
using rle(). That is, before collapsing the digits, you have something
like
>foo
[1] 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 0
Then rle(foo) will show you where the boring lead-zeros end, and you can
use that value to set the truncation ---- rather than a fixed [1:17] as
below.
Carl
quote:
This was what I was looking for to solve the truncate to 17 digits.
Thanks a lot.
Now my output looks like this:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ,0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 ,0.0998004
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 ,0.1996008
On Thu, Sep 25, 2008 at 4:28 PM, Christos Hatzis <
christos.hatzis_at_nuverabio.com> wrote:
> paste(rev(as.integer(intToBits(as.integer(x))[1:17])), collapse="")
endquote
More information about the R-help
mailing list