[R] Bytes to Numeric/Float conversion
murdoch.duncan at gmail.com
Wed Jun 12 13:20:28 CEST 2013
On 13-06-12 6:54 AM, Bikash Agrawal wrote:
> Actually I am using rJava, running some map-reduce using R.
> The data send is in bytes, but actually it is floating-point number.
> On R side, I need to convert this byte into Float. But I couldn't find any
> I am try using rawToChar() which convert into character. And later on
> as.double to convert it.
> But it is not giving the exact value.
> Could any one help me out.
If you want exact transfer from bytes, use raw connections. For example:
> con <- rawConnection(raw(0), "r+")
> writeBin(pi, con)
 18 2d 44 54 fb 21 09 40
> readBin(con, "numeric")
Depending on how you created the bytes, you may need to do some fiddling
with the optional parameters size and endian of readBin to read them
More information about the R-help