例如:
to.read = file('http://www.ats.ucla.edu/stat/r/faq/bintest.dat', 'rb')
a = readBin(to.read, 'raw', n=8)
print(a)
close(to.read)
# [1] 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
我想将其打印为:
00000001 00000000 00000010 00000000 ...
通过一些后期处理,rawToBits
可以使用:
x <- raw()
(y <- readBin(writeBin(1:10,x),"raw",n=8))
[1] 01 00 00 00 02 00 00 00
sapply(y,function(x) paste(as.integer(rev(rawToBits(x))),collapse=""))
[1] "00000001" "00000000" "00000000" "00000000" "00000010" "00000000" "00000000"
[8] "00000000"