0

I want to save a matrix in csv format through write.table function. Using the following command, the column names move one cell back. Is there any way to keep the column names intact? Thanks

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 = ","
  )
MYaseen208
  • 22,666
  • 37
  • 165
  • 309

1 Answers1

0

What about this?:

write.table(
 x=mdat
 , file = "mdat.csv"
 , sep = ",",row.names=c("row1","row2")
)
DatamineR
  • 10,428
  • 3
  • 25
  • 45