-1

我有一个mat精确到小数点后 12 位的纬度/经度坐标矩阵。我的目标是将矩阵转换为保持这些数字完整的 JSON。

> head(mat)
          [,1]     [,2]
[1,] -122.6790 45.51459
[2,] -122.6789 45.51458
[3,] -122.6789 45.51457
[4,] -122.6789 45.51457
[5,] -122.6788 45.51456
[6,] -122.6788 45.51455

> print(head(mat), digits = 15)
                  [,1]             [,2]
[1,] -122.678966434126 45.5145902219176
[2,] -122.678937015334 45.5145823126032
[3,] -122.678907596543 45.5145744032888
[4,] -122.678878177752 45.5145664939744
[5,] -122.678848758960 45.5145585846600
[6,] -122.678819340169 45.5145506753456

然而,简单地使用 toJSON() 只能节省 4 位数。

> toJSON(mat)
[[-122.679,45.5146],[-122.6789,45.5146],[-122.6789,45.5146],[-122.6789,45.5146]...

在 R 中转换为 JSON 时如何保留这些有效数字?

4

1 回答 1

1
library(jsonlite)
toJSON(mat, digits = 12)
于 2017-07-18T17:25:55.333 回答