greennyyy
greennyyy

Reputation: 41

R Write data in a file

I'm trying to save data in a file, but every time I hit the save button, it saves it but keeps deleting the data I already have there. What could be the problem?

 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)

Upvotes: 0

Views: 60

Answers (1)

MS Berends
MS Berends

Reputation: 5269

Use

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

Or

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

Upvotes: 2

Related Questions