1.4 Saving your changes

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.
  • In a production situation, or when changes aren’t being made on a rapid basis, it is common to include the date in the file name.
  • Keep the data, codebook and data management file in the same folder.

The Sys.Date() function takes the current date from your computer. The value is then formatted nicely for human consumption and added (pasted) to the file name before written to the working directory as a new text file.

depress_clean <- depress %>% select(var1, var2, var3)
date <- format(Sys.Date(), "%m%d%y")
filename <- paste("depress_", date, ".txt", sep="")
write.table(depress_clean, filename, sep="\t", row.names=FALSE)

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.