R将数据写入文件

时间:2018-02-18 08:15:17

标签: r

我试图将数据保存在文件中,但每次按下保存按钮时,它都会保存它,但会一直删除我已经拥有的数据。可能是什么问题?

 saveData <- function(data) {
data <- as.data.frame(t(data))
if (exists("responses")) {
  responses <<- rbind(responses, data)
} else {
  responses <<- data
}

 write.csv(responses, file = "read.csv", row.names = FALSE)

1 个答案:

答案 0 :(得分:2)

使用

write.csv(responses, file = "read.csv", row.names = FALSE, append = TRUE)

saveData <- function(data) {
data <- as.data.frame(t(data))
write.csv(data, file = "read.csv", row.names = FALSE, append = TRUE)