Search code examples
rdataframe

How to save a data frame in R?


I made a data frame in R that is not very big, but it takes quite some time to build. I would like to save it as a file, which I can then again open in R. How do I achieve this?


Solution

  • There are several ways. One way is to use save() to save the exact object. e.g. for data frame foo:

    save(foo,file="data.Rda")
    

    Then load it with:

    load("data.Rda")
    

    You could also use write.table() or something like that to save the table in plain text, or dput() to obtain R code to reproduce the table.