Importing/exporting data from R

Sharry Tong
Sep 4, 2018 · 2 min read

This week I continued my tutorials from R for Journalists to learn more about working with R. When it comes to importing and exporting data, R is quite powerful in terms of the types of data it allows to import — CSV, Excel, delimited text, JSON, etc.

With CSV it’s pretty easy to work with. You can either import CSV file by using either a URL or a actual saved file. And with some simple commends, your CSV file will be displayed nice on your screen.

Excel seems like a bit harder to work with comparing to CSV. A package is needed to import it, and mere URL would not work here. You have to have a saved Excel file to import and even after that further data cleaning are needed a lot of time.

Delimited text also needs to be downloaded to import like the Excel file does except it doesn’t seem to need extra packages and can be imported using certain functions. Similar to Excel files, some further cleaning might be needed for this type of data.

A package is required for JSON files, and it can be imported though both URL and local path. The only problem with JSON is that it’s mostly nested and messy. Therefore, some future work are required to make it workable for your need.

SPSS data is something I am not so familiar with, and it seems like it’s mostly used for bigger data sets. Luckily R can handle bigger data and a local file is needed for this case to be imported.

Other than learning about how to import different types of data. Chapter 2 also get briefly started with how to sort and clean data in R. Thanks to the package datapasta making users’ life easier by allowing copying data structured in a table from somewhere else and paste it directly into RStudio. It is also useful to know that R allows users to combine data from multiple spreadsheets into one file with couple functions.

Sharry Tong
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade