Q
在r中导出矩阵
6
A
回答
11
我看不出问题所在。您不会获得新的列,行名称会保存为文本文件中的第一列。因此,要么指定在read.table
中给出行名称的列,要么在write.table
中使用row.names=FALSE
选项。
示范:
mat <- matrix(1:10,ncol=2)
rownames(mat) <- letters[1:5]
colnames(mat) <- LETTERS[1:2]
mat
write.table(mat,file="test.txt") # keeps the rownames
read.table("test.txt",header=TRUE,row.names=1) # says first column are rownames
unlink("test.txt")
write.table(mat,file="test2.txt",row.names=FALSE) # drops the rownames
read.table("test.txt",header=TRUE)
unlink("test2.txt")
在任何情况下,阅读帮助文件会告诉你这一切。
2
我假设“新列”是指默认情况下写出的行名。要取消它们,请在致电write.table
或write.csv
时设置row.names = FALSE
。
write.table package:utils R Documentation
Data Output
Description:
‘write.table’ prints its required argument ‘x’ (after converting
it to a data frame if it is not one nor a matrix) to a file or
connection.
Usage:
write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
eol = "\n", na = "NA", dec = ".", row.names = TRUE,
col.names = TRUE, qmethod = c("escape", "double"))
write.csv(...)
write.csv2(...)
...
row.names: either a logical value indicating whether the row names of
‘x’ are to be written along with ‘x’, or a character vector
of row names to be written.
col.names: either a logical value indicating whether the column names
of ‘x’ are to be written along with ‘x’, or a character
vector of column names to be written. See the section on
‘CSV files’ for the meaning of ‘col.names = NA’.
+0
hehe,+1用于实际复制帮助文件。但''write.table'已经足够... –
相关问题
- 1. 在矩阵中存储矩阵R
- 2. R:在矩阵
- 3. R输出相异矩阵
- 4. 在R中连接矩阵
- 5. 在R中制作矩阵
- 6. 在R中处理矩阵
- 7. 矩阵中的R
- 8. 矩阵R中计算矩阵
- 9. 将R中的矩阵导出为excel工作簿
- 10. Oracle导出导出兼容性矩阵
- 11. R矩阵积
- 12. 重复载体导入矩阵R
- 13. R矩阵包:Demean稀疏矩阵
- 14. R:矩阵的对矩阵3D图
- 15. 如何从矩阵R中
- 16. R - 矩阵中的回路
- 17. R中的减法矩阵
- 18. 矩阵行中的R
- 19. R中空表的矩阵
- 20. R中的矩阵的逆
- 21. R编程中的矩阵
- 22. R中的矩阵点积
- 23. 从其中R矩阵
- 24. 转换矩阵中的R
- 25. r中的矩阵乘法
- 26. 混淆矩阵为R中
- 27. R中的矩阵函数
- 28. R中的矩阵功率
- 29. 距离矩阵中的R
- 30. R中矩阵的排名
+1不用于复制帮助文件 –
不需要粗鲁的 - 例如我没有检查文档,但对于write.matrix,并没有这样的选项 –