On 6/24/2009 2:41 PM, Sean Davis wrote:
A simple question, I hope.... I have a binary file format that I want to slurp into R using readBin. There are a couple of fields in the file that are 4-byte floats. Since R has no "float" data type (4-byte), I am wondering how to go about this task. I could simply do all the work in C, but the format is pretty simple, so I wanted to do it using just R. I did see as.single, but it appears that is for passing things to C and not much more. Any suggestions appreciated.
You can specify the size when reading a float using readBin(what="numeric", size=4). It will read a single, then convert it to double to store in R. You may need to set the endian value too, if the byte order is wrong.
Duncan Murdoch ______________________________________________ R-help@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.