数据文件data.dat
:
5625010350032.36719 5627008621379.12591 5628763999478.55791 5630383772880.98831 5632384688238.96095 5633992371569.87936 5635830220975.76879 5637713568911.67183 5639436594135.51215 5641160625591.58400 5643072053703.23919 5644920788572.33232 5646668772882.99855 5648398453919.33759 5650178043246.84799 5651842484825.03887 5653671759113.42399 5655374735235.55599 5657184594518.72287 5658951103084.33839 5660687853998.58127 5662491073242.24399
下面的代码
x1 <- data.matrix(data.table::fread("data.dat")) # Read it
plot(x1[1,])
data.table::fwrite(x=x1, file="xout.dat", sep=" ") # Write it
x2 <- data.matrix(data.table::fread("xout.dat")) # Read it again
lines(x2[1,], col='red')
显示元素x2[1,13]
接受值2.7898250541260385e-311
,而实际上它应该等于x1[1,13]
.是什么导致引入垃圾值?
data.dat
个文件是从C++文件中按以下方式编写的
std::ofstream file("data.dat", std::ios::out);
file << std::setprecision(std::numeric_limits<long double>::digits10) << std::showpoint;
for (size_t i = 0; i < v.size(); ++i)
file << v[i] << " ";
file << std::endl;
其中,向量v
包含写入data.dat
的值.我在使用数据.表1.14.2版和R 4.1.3版.