1.15 Export and Save

You’ve just made a ton of changes!

  • Save or export the new data set to your computer.
  • Edit the codebook to reflect the changes that you made.
  • Keep the data, codebook and data management file in the same folder.
depress_clean <- depress %>% select(var1, var2, var3)

# Save as a .Rdata file for later use in R
save(depress_clean, "data/depress_clean.Rdata") 

Now every time you run your data cleaning script file, it will make all the changes and save/overwrite the depress_clean.Rdata data file. This ensures that any analysis script that uses this data has the most up to date varibles.

Need to export to a different software program? Look into the haven package.

SPSS users commonly save cleaned data as a .sav format.

SAVE outfile='FilePath\depress_sysdate.sav'
/KEEP = Variable_Name1 Variable_Name2.

Saving only selected variables

  • In SPSS the /KEEP statement demonstrated above only writes the variable names listed to the saved data set. This can be very useful when dealing with data sets with a large number of variables.
  • For R users, using dplyr select is generally the fastest.