我正在尝试将二进制文件读入R,但是该文件具有用二进制代码编写的数据行。因此,它没有属于一列的完整数据集,而是存储为数据行。这是我的数据:
字节1-4:int ID字节5:char响应字符字节6-9:int Resp Dollars字节10:char类型char
任何人都可以帮助我弄清楚如何将此文件读入R?
嗨,大家好,
这是到目前为止我测试过的代码。我尝试了几件事,但收效甚微。不幸的是,我不能将任何数据发布在公共网站上,抱歉。我是R的新手,因此在如何改进代码方面需要一些帮助。提前致谢。
> binfile = file("File Location", "rb")
> IDvals = readBin(binfile, integer(), size=4, endian = "little")
> Responsevals = readBin(binfile, character (), size = 5)
> ResponseDollarsvals = readBin (binfile, integer (), size = 9, endian= "little")
Error in readBin(binfile, integer(), size = 9, endian = "little") :
size 9 is unknown on this machine
> Typevals = readBin (binfile, character (), size=4)
> binfile1= cbind(IDvals, Responsevals, ResponseDollarsvals, Typevals)
> dimnames(binfile1)[[2]]
[1] "IDvals" …Run Code Online (Sandbox Code Playgroud)