【发布时间】:2011-10-05 14:54:22
【问题描述】:
我在内存中有一个对称矩阵 (4x4)。不幸的是, sum( originalMatrix != t( originalMatrix ) ) = 6。所以我输入了那个矩阵并将其读回内存。现在 sum( dputMatrix!= t( dputMatrix) ) = 0。这怎么可能?如何测试内存中矩阵的对称性?
originalMatrix = ...
sum( originalMatrix != t( originalMatrix ) ) # results in 6
dput( originalMatrix )
dputMatrix = structure(c(0.00117771346463494, -1.57864028664711e-05, 0.000293652924987303,
-9.85387333663002e-05, -1.57864028664711e-05, 0.000194782042576016,
6.9133672862693e-05, 4.23792732612071e-05, 0.000293652924987303,
6.9133672862693e-05, 0.00046216043028767, 2.70172523991749e-05,
-9.85387333663002e-05, 4.23792732612071e-05, 2.70172523991749e-05,
0.00017694896679169), .Dim = c(4L, 4L), .Dimnames = list(c("a00088630",
"a0091n", "a01010", "a01307810"), c("a00088630", "a0091n", "a01010",
"a01307810")))
sum( dputMatrix != t( dputMatrix ) ) # results in 0!!!
【问题讨论】:
-
我发现 all.equal 对于 originalMatrix 和 dputMatrix 测试都返回 TRUE
-
看起来 R FAQ 7.31 适用。 cran.r-project.org/doc/FAQ/R-FAQ.html
-
我知道这个问题,但无法理解为什么 dput 版本有效。感谢您指向常见问题解答!我认为这句话解释了它:“......除非它们是由相同的算法计算的”。 dput 版本让 R 有机会以我猜想的方式将数字读入内存。
-
是的,dput 只写入低精度。使用 save() 准确地写出 R 对象。
-
谢谢!您能否发布您的两个 cmets 作为答案,以便我接受?
标签: r