Introduction to R Programming

What is R & RStudio?

Installing R & RStudio

Getting Started

R Packages

An R package contains a collection of functions and datasets developed by the community. These packages can be downloaded and directly used by calling their specific function or dataset names.

How to Install an R Package

install.packages("packagename")

Upon successful download, type the following line:

library(packagename)

If you are confused about what a package does, you can use help(package = "<package_name>") to get more information. To understand what a function does, you can use help("<function_name>") or type ?<function_name> or ?<package_name> to open the "Help" window and see the R Documentation description for the package or function.

Importing Data

Importing

To import an Excel file in .xlsx or .xls format, download the "readxl" package and use the read_excel function.

To import Stata (.dta), SPSS (.sav), and SAS (.xport) files, download the "haven" package. Use the read_dta function for Stata, read_spss function for SPSS, and read_xpt function for SAS, respectively.

Exporting Data

Marriott Library Eccles Library Quinney Law Library