R hdf5数据集写错了吗? [英] R hdf5 dataset written incorrectly?

查看:71
本文介绍了R hdf5数据集写错了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行以下代码时,我的预测变量"数据集将正确填充:

When I execute the following my "predictors" dataset is populated correctly:

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)生成的(正确)输出为:

The generated (correct) output for head(predictors) is:

            [,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

但是,当我阅读它时,结果不正确:

However, when I read it the results are not correct:

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查看器也为预测变量"数据集显示了这个不正确的值.

How come what I write does not correspond to what I get back? I double-checked and hdfview HDF5 viewer also shows this incorrect values for the "predictors" dataset.

这是怎么了?

推荐答案

来自

请注意,数组在打开时显示为转置矩阵 使用C程序(h5dump或HDFView).这是由于事实 C上变化最快的维度是最后一个维度,而R上是 第一个(例如在Fortran中).

Please note, that arrays appear as transposed matrices when opening it with a C-program (h5dump or HDFView). This is due to the fact the fastest changing dimension on C is the last one, but on R it is the first one (as in Fortran).

这篇关于R hdf5数据集写错了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆