> writeBin(1:3, raw(), size=4, endian="little")
[1] 01 00 00 00 02 00 00 00 03 00 00 00
> writeBin(c(1,2,3), raw(), size=4, endian="little")
[1] 00 00 80 3f 00 00 00 40 00 00 40 40
> writeBin(c(1:3), raw(), size=4, endian="big")
[1] 00 00 00 01 00 00 00 02 00 00 00 03
> writeBin(c(1,2,3), raw(), size=4, endian="big")
[1] 3f 80 00 00 40 00 00 00 40 40 00 00
第一个和第三个结果是我所期望的,但为什么我得到一个指定为c(1,2,3)的向量的不同原始向量?
答案 0 :(得分:6)
可能是因为一个存储为整数,另一个存储为double:
typeof(1:3)
typeof(c(1,2,3))
typeof(c(1L,2L,3L))