当我从数据框或数据 table 转换为矩阵时,为什么大整数会在 R 中变形?

Why do big integers get deformed in R when I convert from a data frame or data table to a matrix?

  1. 我有一个完全由数字列(双精度和整数列)组成的数据框(尺寸为 1 x 30)。有些整数是 10^12.
  2. 当我使用基数 R 的 as.matrix() 函数将数据框转换为矩阵时,发生了一些奇怪的事情,例如这里的整数 10978645435 在新对象中不会保持不变(数字矩阵)但它变为 5.076377571e-314

知道为什么会发生这种情况以及如何解决这个问题吗?提前致谢。

嗨,也许你应该看看 Why are values changing when converting from data.frame to a numeric matrix?

看看 Alex A. 的回答,告诉我它是否对您有帮助。我还认为这是因为您的数据框中的数值被视为因素。

A​​lex A. 的代码:y <- apply(as.matrix(x[, 1:5]), 2, as.numeric)

编辑:没关系,您似乎已经找到问题了。