Chapter 6
LURN… To Export a Dataset

This chapter assumes you’ve got some data to export, and I mean data; not results from analyses which is discussed in Chapter 9. You may also wish to use this information once you know how to tabulate various numerical summaries, discussed in Chapter 8.

6.1 Creating external files

This section is just the inverse action of importing data from an external file as discussed in Chapter 4. All the read type commands have corresponding write commands.

If you read Chapter 4 you’ll know that my preference is to use files that are easily transferred and easily checked for their accuracy using other software. In particular, I prefer to create comma separated value (csv) files using the write.csv() command. If there was a data.frame called Chickens in my current workspace that I wanted to export for sharing with another user, I would issue the following command.

  > write.csv(Chickens, file="chickens.csv")

If R had created rownames for the data.frame, I might not want to include them. A simple additional argument is all that is required.

  > write.csv(Chickens, file="chickens.csv", row.names=FALSE)

If another file type is required then the help page for write.csv() may be useful. This page also gives the help on the write.table() command.

6.2 Exporting data for use in alternative software

The better statistical software options allow users to import data from a range of sources and file types. If for some (very strange) reason you need to create files in a specific format for importing into another statistics package then you will need to investigate the foreign package.