# Hello, World/Importing Data in R

Published:

Hello, world! I have finally figured out GitHub and how to make a free website with Jekyll. It’s a great day!

Today, I would like to point everyone to my favorite R package for importing data: the rio package. It’s my favorite because the syntax is basically the same, no matter what type of data file you are trying to load.

To import a .csv file:

library(rio)
data1 <- import("data1.csv")


To import a Stata dataset, all you need to do is change the extension to .dta.

library(rio)
data2 <- import("data2.dta")


For Excel files, you just need to change the extension to .xlsx or .xls (depending on the file), as well as specify which tab you are attempting to reference with “which”. This is necessary because Excel files can have multiple tabs, whereas that is not possible for a .csv file. Here is some code for referencing the second tab in an Excel workbook:

library(rio)
data3 <- import("data3.xlsx", which=2)


I hope this information helps someone. For more information, refer to the rio package help file.

Tags: