将矩阵保存到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.5but 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+06Is 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=",")更多推荐
发布评论