我有一个lat / lon坐标矩阵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时如何保留这些有效数字?
答案 0 :(得分:1)
library(jsonlite)
toJSON(mat, digits = 12)