R Tutorial 1: Introduction and Setup of R

Introduction to R

What is R? Why R?

What is R? R is a programming language and environment with extensive libraries of preprogrammed tools for statistical analysis, data manipulation and data visualisation. Why do business student need R? With terabytes of sales or financial data, most businesses are trying to make sense of the large amount of information they manage to collect from their customers as well as their operations. Excel is too slow and unwieldy. SAS is paid. R is free and filled with packages that you can easily implement. The choice is obvious.

Installing R

First you need to install R

Step 1: Go to https://cran.r-project.org/ and pick the download for whichever OS you are using

Step 2: Go into the subdirectory call “base” (highlighted below)

Step 3: Click on Download R and install the program with all the default settings

Then you need to install RStudio at https://www.rstudio.com/ R itself is just the backend of the R programming language, whereas RStudio is the tool required to write code in R

Step 1: Go to https://www.rstudio.com/ and click on download under R Studio

Step 2: Press Download for RStudio Desktop (Open Source License)

Step 3: Pick the installer for your system and install it with default settings

What’s a script?

A R script is simply a text file that contains the commands you want to send to the R compiler, which we will be able to create with R Studio.

1. Scripting Pane

This is where you can type in the file for the commands and program that you will like for R to run. One interesting thing is that instead of having to run the entire script from top to bottom as usual programming language goes, you can isolate out portion/single lines of code to run. This is not open when you first open RStudio, so you should go open a new R script from files to gain access.

2. Console Pane

This is the console of R, where you can type in R commands too. Usually we use the console for some debugging after we run a R script. *

3. Environment Pane

This is where you manage your data, be it as excel, csv, or imported from database. They will show you the number and columns of the data tables you have uploaded or created during the course of your data analysis.

4. Files and Directory Pane

Where everything else go. Need help for some R command? It’s under Help. Installing packages? It’s under packages. Just plotted some data? You can view it under viewer.

Getting Help

Getting help for R is very simple due to the in-built help database in R Studio. There are some ways to do it quickly while you are learning R

  1. Go to console, type help(“whatever you need help with”) and press enter. If there is documentation for it, it will appear at the files and directory pane
  2. Go to help tab in the files and directory pane, and enter whatever things you need help with in the field.
  3. Google is your best friend (More specifically, stackoverflow. If your question is not already answered there, you can just ask it there, it usually get answered in a night)

Next: Tutorial 2 Working Environment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s