I don't know whether this is an integer64
(from bit64
) problem, or a melt problem (from reshape2
, but if I try to reshape a data.frame containing integer64 data then the class information is destroyed in the process and it reverts to the double representation:
library(bit64)
library(reshape2)
DF = data.frame(I =letters, Num1 = as.integer64(1:26), Num2 = as.integer64(1:26))
DFM = melt(DF, id.vars = "I")
sapply(DF, class)
sapply(DFM, class)
gives:
> sapply(DF, class)
I Num1 Num2
"factor" "integer64" "integer64"
> sapply(DFM, class)
I variable value
"factor" "factor" "numeric"
And because integer64 is double underneath, the data is "corrupted"
> DF
I Num1 Num2
1 a 1 1
2 b 2 2
3 c 3 3
4 d 4 4
5 e 5 5
...
> DFM
I variable value
1 a Num1 4.940656e-324
2 b Num1 9.881313e-324
3 c Num1 1.482197e-323
4 d Num1 1.976263e-323
5 e Num1 2.470328e-323
6 f Num1 2.964394e-323
What is causing this? Is this a integer64
problem or a melt
problem? When creating classes what can be done to avoid this sort of thing?