将矩阵保存到R中的.csv文件而不会丢失格式(Save matrix to .csv file in R without losing format)

编程入门 行业动态 更新时间:2024-10-26 13:18:49
矩阵保存到R中的.csv文件而不会丢失格式(Save matrix to .csv file in R without losing format)

我正在尝试使用MASS的write.matrix将矩阵写入.csv文件,但我遇到了一些问题。 当我打印矩阵时,它看起来像这样

p q s S2 R2 R2adj Cp AIC PRESS 1 0 1 167.27779 27981.8583 NA NA 3679.294476 NA NA 2 1 2 160.32254 25703.3165 0.08866209 0.08142925 3343.909110 1666.993 3338167.3 3 1 2 86.73559 7523.0630 0.73326195 0.73114498 891.016823 1509.726 1045980.3 4 1 2 67.50458 4556.8690 0.83843145 0.83714916 490.815893 1445.555 693993.5

但是当我write.matrix(moDat2, file = paste(targetPath, "dat2.csv", sep="/"), sep=",")

它将它保存到这样的文件中

p,q,s,S2,R2,R2adj,Cp,AIC,PRESS 0.000000e+00,1.000000e+00,1.672778e+02,2.798186e+04, NA, NA,3.679294e+03, NA, NA 1.000000e+00,2.000000e+00,1.603225e+02,2.570332e+04,8.866209e-02,8.142925e-02,3.343909e+03,1.666993e+03,3.338167e+06 1.000000e+00,2.000000e+00,8.673559e+01,7.523063e+03,7.332620e-01,7.311450e-01,8.910168e+02,1.509726e+03,1.045980e+06

无论如何我可以将它保存到文件而不将数据转换为科学记数法吗?

I'm trying to write a matrix to a .csv file using the write.matrix from MASS but I'm having some problems. When I print the matrix it look something like this

p q s S2 R2 R2adj Cp AIC PRESS 1 0 1 167.27779 27981.8583 NA NA 3679.294476 NA NA 2 1 2 160.32254 25703.3165 0.08866209 0.08142925 3343.909110 1666.993 3338167.3 3 1 2 86.73559 7523.0630 0.73326195 0.73114498 891.016823 1509.726 1045980.3 4 1 2 67.50458 4556.8690 0.83843145 0.83714916 490.815893 1445.555 693993.5

but when I do write.matrix(moDat2, file = paste(targetPath, "dat2.csv", sep="/"), sep=",")

It save it to the file like this

p,q,s,S2,R2,R2adj,Cp,AIC,PRESS 0.000000e+00,1.000000e+00,1.672778e+02,2.798186e+04, NA, NA,3.679294e+03, NA, NA 1.000000e+00,2.000000e+00,1.603225e+02,2.570332e+04,8.866209e-02,8.142925e-02,3.343909e+03,1.666993e+03,3.338167e+06 1.000000e+00,2.000000e+00,8.673559e+01,7.523063e+03,7.332620e-01,7.311450e-01,8.910168e+02,1.509726e+03,1.045980e+06

Is there anyway I can save it to the file without the data getting transform to scientific notation?

最满意答案

您可以在write.matrix调用中使用format 。

write.matrix(format(moDat2, scientific=FALSE), file = paste(targetPath, "dat2.csv", sep="/"), sep=",")

You can use format inside your write.matrix call.

write.matrix(format(moDat2, scientific=FALSE), file = paste(targetPath, "dat2.csv", sep="/"), sep=",")

更多推荐

本文发布于:2023-08-03 14:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1392010.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矩阵   格式   文件   csv   Save

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!