I know there is no float in R. so How can I read float data from a binary file. the struct of data in C as follows
typedef struct
{
int date;
int open;
int high;
int low;
int close;
float amount;
int vol;
int reservation;
} StockData;
to.read = file(filename, "rb");
line1=readBin(to.read, "int",8);
amount is not the right value. how can I get the right value as float?
Your C structure is made of 5 integer values followed by a float and then 2 integers again. So, you can call readBin three times:
line1<-c(readBin(to.read,"int",5),
readBin(to.read,"double",1,size=4),
readBin(to.read,"int",2))
You handle the float value by setting the size argument to 4, since a float has a size of 4 bytes (instead of the 8 of a double).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With