2013-05-18 92 views
0

我想通過write.table函數保存csv格式的矩陣。使用以下命令,列名移回一個單元格。有沒有辦法保持列名完好?由於用適當的行列標題保存矩陣

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 = "," 
) 

回答

0

這個怎麼樣?:

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