saving a data file in R

Roswitha Blasche picture Roswitha Blasche · Apr 6, 2011 · Viewed 21.8k times · Source

I have successfully loaded a .txt file into R. I want to save the data so I can actually actively use it. What is the command for saving a file? Will I save the file to one of the existing packages (UsingR, MASS), or just as a separate file?

Answer

Joris Meys picture Joris Meys · Apr 6, 2011

The command you look for is either one of these :

  • save() : saves the mentioned objects as R objects (extension .RData). These files are binary and can be read very quickly again with load()
  • write() : is a wrapper for cat() and is used to create text files from objects, usually matrices.
  • write.table() and write.csv() : are commands to write data frames as text files with a specific separator.

Check also sink(), used to redirect other output to a file (usually used for logging purposes).

Please read the manuals of R :

http://cran.r-project.org/doc/manuals/R-intro.pdf

http://cran.r-project.org/other-docs.html

Related questions :