Skip to Main Content

Data Science

A guide to library resources about Data Analytics

Introduction to R & RStudio

  • About R & RStudio

         -- R is a programming language for data analysis

            Some basic functionalities

         -- RStudio is an integrated development environment (IDE) for R

            Do all "coding" in RStudio

         -- Strength of R is in its packages - Over 12,000 packages

         -- RStudio is not R. But it facilitates the use of R

  • Start RStudio
  • Under the File menu at top left, click on New Project, choose New Directory, then New Project
  • As directory (or folder) name enter r-intro and create project as subdirecory of your desktop folder: ~/Desktop
  • Click on Create project
  • Under the Files tab on the bottom right of the screen, click on New Folder and create a folder named data within your newly created working directory (e.g., ~/r-intro/data)
  • On the main menu go to Files > New File > R Script (or use the shortcut Shift + Ctrl/Cmd N) to open a new file
  • Save the empty script as r-intro-script.R in your working directory.

Your working directory should now look like in the following Figure: 

You may need to install.packages(“pkgname”) before you can load them

E.g. library(readr), library(readxl)      

  • Using RStudio Import Tools

File/Environment -> Import Dataset -> From text, Excel……-> Enter a URL/file path

  • Importing Flat Files:

Import the HRS data from a .csv file

# Import the HRS data from a .csv file

      hrs = read.csv(“C:/HRS r1bmi.csv”, header=T, sep=“,”)

# Look at the first 6 cases to check the data

      head(hrs)

# Look at the last 6 cases to check the data

      tail(hrs)

  • Density plot and Q-Q plot to check normality
  • Box plot to detect outliers
  • Scatter plot to visualize the linear relationship between the dependent and independent variables

Engel, C. A. (2019, February 4). R and Rstudio. GitHub. https://cengel.github.io/R-intro/backgroud.html.

Need an Instruction/Consultation in Data Analytics?

Please visit this page if you need an instruction/consultation in Data Analytics.