我试图将数据保存在文件中,但每次按下保存按钮时,它都会保存它,但会一直删除我已经拥有的数据。可能是什么问题?
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)
答案 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)