我正在尝试将二进制文件读入R,但是此文件具有以二进制代码写入的数据行。所以它没有一组属于一列的完整数据,而是存储为数据行。这里是我的数据是什么样子:将二进制文件读入R
字节1-4:INT ID 字节5:焦炭响应特性 字节6-9:INT RESP美元 字节10: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" "Responsevals" "ResponseDollarsvals" "Typevals"
> colnames(binfile1)=binfile
Error in `colnames<-`(`*tmp*`, value = 4L) :
length of 'dimnames' [2] not equal to array extent
你可以发布数据文件的前几行吗? – Seth
将它作为readBin的原始字节读取,并将其推入与文件相同的nrow矩阵中,然后将readBin从多组列中读入。它很快。这基本上为更复杂的格式,删除所有标题的东西和slurp了:http://stackoverflow.com/questions/12931979/reading-binary-files-in-r – mdsumner
提供的文件,我会放在一起一个例子。 – mdsumner