Chapter 5 Data Import and Export
Learning Objectives
After completing this chapter, you will be able to:
- Explore and summarize datasets using
head(),summary(), andstr() - Export data to CSV, Excel, and other delimited file formats
- Import data from CSV, Excel, SPSS, SAS, and Stata files
- Save and restore R objects and workspaces using
save()andload()
So far in this book, you have been creating objects by yourself. When working on real projects, you often need to import existing data into R, or export the created objects or analysis results into a file on the computer. In this chapter, you will learn how to import and export data of different file types.
At a glance – Chapter ROADMAP
Section 5.1. Introduction to Datasets: Explore and summarize built-in and package datasets.
Section 5.2. Exporting: Save data to delimited files like CSV.
Section 5.3. Importing: Read data from delimited files into R.
Section 5.4. Excel Files: Work with.xlsxand.xlsfiles.
Section 5.5. Other Formats: Import from SPSS, SAS, and Stata.
Section 5.6. R Objects & Workspace: Save and restore any R object or your entire environment.