writeBin raw()对于1:3和c(1,2,3)有什么不同?

时间:2013-06-23 17:15:42

标签: r

> 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)的向量的不同原始向量?

1 个答案:

答案 0 :(得分:6)

可能是因为一个存储为整数,另一个存储为double:

typeof(1:3)
typeof(c(1,2,3))
typeof(c(1L,2L,3L))