An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130611/4ce44875/attachment.pl>
Bytes to Numeric/Float conversion
6 messages · Bikash Agrawal, David Winsemius, Henrik Bengtsson +2 more
On Jun 11, 2013, at 9:01 AM, Bikash Agrawal wrote:
Is there any packages available in R, that can convert Bytes array to Float. Using rJava we can do it. But it is kind of slow. Is there any R specific packages. I am having problem converting my bytes array to floating point. Could any one help me with this problem.
There is a raw data type that is designed to hold bytes than can be indexed. ?raw `scan` can read files of type raw ?scan
David Winsemius Alameda, CA, USA
On Tue, Jun 11, 2013 at 2:14 PM, David Winsemius <dwinsemius at comcast.net> wrote:
On Jun 11, 2013, at 9:01 AM, Bikash Agrawal wrote:
Is there any packages available in R, that can convert Bytes array to Float. Using rJava we can do it. But it is kind of slow. Is there any R specific packages. I am having problem converting my bytes array to floating point. Could any one help me with this problem.
There is a raw data type that is designed to hold bytes than can be indexed. ?raw
...and then ?readBin /Henrik
`scan` can read files of type raw ?scan -- David Winsemius Alameda, CA, USA
______________________________________________ R-help at r-project.org 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.
I recommend the hexView package for setting up such conversions.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
David Winsemius <dwinsemius at comcast.net> wrote:
On Jun 11, 2013, at 9:01 AM, Bikash Agrawal wrote:
Is there any packages available in R, that can convert Bytes array to
Float.
Using rJava we can do it. But it is kind of slow. Is there any R specific packages. I am having problem converting my bytes array to floating point. Could any one help me with this problem.
There is a raw data type that is designed to hold bytes than can be indexed. ?raw `scan` can read files of type raw ?scan
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130612/569b7571/attachment.pl>
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 function. 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) > rawConnectionValue(con) [1] 18 2d 44 54 fb 21 09 40 > seek(con,0) [1] 8 > readBin(con, "numeric") [1] 3.141593 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 properly. Duncan Murdoch