使用适当的行和列标题在r中保存矩阵

时间:2013-05-18 08:36:39

标签: r matrix

我希望通过csv函数以write.table格式保存矩阵。使用以下命令,列名称将一个单元格移回。有没有办法保持列名完整?感谢

mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol = 3, byrow = TRUE,
               dimnames = list(c("row1", "row2"),
                               c("C.1", "C.2", "C.3")))
mdat

write.table(
    x=mdat
  , file = "mdat.csv"
  , sep = ","
  )

1 个答案:

答案 0 :(得分:0)

这个怎么样?:

write.table(
 x=mdat
 , file = "mdat.csv"
 , sep = ",",row.names=c("row1","row2")
)