Writing Data Files

To export data from R, use write.table() function

# write.table(dataframe, file="filename", sep="", row.names=T, col.names=T) writes out a dataframe to the file "filename" with rows and column labels
write.table(data, file="newdata.txt")

Important options are:

  • sep : the field separator character
  • row.names : logical. Whether to include row.names or not
  • col.names : logical. Whether to include col.names or not

To save data as a .csv file, include sep=“,” argument.

write.table(data, file="newdata.csv", sep=",", row.names=T, col.names=T)
write.table(data, file="newdata.csv", sep=",", row.names=F, col.names=F)