3

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?

0

1 Answer 1

5

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).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.