1

我有以下因素:

> str(prediction)
 Factor w/ 2 levels "0","1": 2 1 1 1 1 1 1 2 1 1 ...
 - attr(*, "names")= chr [1:9000] "1" "2" "3" "4" ...

我希望得到一个 9000 x 1 向量的 1 或 0 的 csv。

我试过了:

write.table(prediction, file = "prediction-1-Decision-Tree-08-Oct-2013.csv", sep = ",", col.names = NA, qmethod = "double")

但这给了我一个带有两列和标题的csv:

"","x"
"1","1"
"2","0"
"3","0"
"4","0"
"5","0"
etc.

我希望没有标题,只有一列。

4

1 回答 1

2

您快到了!只需添加row.names=FALSE到您的 write.table 调用:

write.table(prediction, file = "prediction-1-Decision-Tree-08-Oct-2013.csv", sep = ",", col.names = NA, qmethod = "double"
           , row.names=FALSE)

您看到的不是列,而是原始R对象的 row.names。以供将来参考,有两件事会泄露这些是行名而不是​​数据的事实 - 好吧 3,如果你算上手册;)

  • 该列的标题是""
  • 这些数字是连续的,从 1 开始(如果没有给出明确的行名,这是人们所期望的)
于 2013-10-08T14:16:54.550 回答