R hdf5数据集写得不正确?

时间:2013-08-21 14:11:08

标签: r hdf5

执行以下操作时,我的“预测变量”数据集正确填充:

library(rhdf5)
library(forecast)
library(sltl)
library(tseries)

fid <- H5Fcreate(output_file)
## TODO: compute the order p
p <- 4
# write predictors
h5createDataset(output_file, dataset="predictors", c(p, length(tsstl.remainder) - (p - 1)), storage.mode='double')
predictors <- as.matrix(tsstl.remainder)
for (i in 1:(p - 1)) {    
    predictors <- as.matrix(cbind(predictors, Lag(as.matrix(tsstl.remainder), i)))
}
predictors <- as.matrix(predictors[-1:-(p-1),])
head(predictors)
h5write(predictors, output_file, name="predictors")
H5Fclose(fid)

head(predictors)的生成(正确)输出为:

            [,1]        [,2]        [,3]       [,4]
[1,]   0.3089645   6.7722063   5.1895389  5.2323261
[2,]   8.7607228   0.3089645   6.7722063  5.1895389
[3,]  -0.9411553   8.7607228   0.3089645  6.7722063
[4,] -14.1390243  -0.9411553   8.7607228  0.3089645
[5,] -26.6605296 -14.1390243  -0.9411553  8.7607228
[6,]  -8.1293076 -26.6605296 -14.1390243 -0.9411553

然而,当我读到它时结果不正确:

tsmatrix <- t(as.matrix(h5read(output_file, "predictors")))
head(tsmatrix)

输出错误:

            [,1]      [,2]       [,3]      [,4]
[1,]   0.3089645  8.760723 -0.9411553 -14.13902
[2,] -26.6605296 -8.129308 -9.8687675  31.52086
[3,]  54.2703126 43.902489 31.8164836  43.87957
[4,]  22.1260636 36.733055 54.7064107  56.35158
[5,]  36.3919851 25.193068 48.2244464  57.12196
[6,]  48.0585673 72.402673 68.3265518  80.18960

为什么我写的东西与我得到的东西不符?我仔细检查了hdfview HDF5查看器也显示了“预测变量”数据集的错误值。

这里有什么问题?

1 个答案:

答案 0 :(得分:4)

来自rhdf5 docs

  

请注意,打开时,阵列显示为转置矩阵   使用C程序(h5dump或HDFView)。这是因为事实   C上最快的变化维度是最后一个,但在R上它是   第一个(如在Fortran中)。