top of page
Image by Arnold Francisca
RStudio logo.png

Installation & Set-up

R is a programming language used for statistical computing while RStudio uses the R language to develop statistical programs. In R, you can write a program and run the code independently of any other computer program. RStudio however, must be used alongside R in order to properly function.

We will use RStudio for statistical intrepretaion of our Data.

CRAN.png

- Installation -

  1. Download R Package from CRAN-R as per your system compatibility - https://cran.r-project.org/

  2. Install R Package

  3. Do not run R-Package

  4. Download RStudio - https://www.rstudio.com/products/rstudio/download/

  1. Install RStudio

  2. Run RStudio

Install RStudio.png

RStudio Workspace

After you run the RStudio, access the tool from Start menu.

The RStudio workspace have 4 sections as elaborated below :

Rscript - This section is used for runnng the R Codes. We can launch a new script and save it from File option from top left corner fo the page.

Console - The output of codes run in RScript will reflect in Console.

Environment - The details of Data files created/imported in RStudio will reflect in Environment. 

This section also have tabs for History and Connections to various data sources.

Files, Packages & Plot - This section reflects the files/folders on you system, the Plot Visuals run over any dataset and RStudio Packages/Libraries installed for various functions.

RStudio.png

RStudio Appearance

For Windows 10

Pane Icon.JPG

We can modify the workspace colour and appearance as we need.

Go to Workspace Layout icon at the top of the script (besides add-ins) - Click on Pane Layout - Appearance - Alter the Editor Theme, Size and so on as per your requirements.

I like to use Cobalt or Solarized Light mostly.

RStudio Workspace.png
RStudio Layout.png

RStudio Pane Layout

For Windows 10

Pane Icon.JPG

We can interchange the RStudio Panes as per our requirements too.

Go to Workspace Layout icon at the top of the script (besides add-ins) - Click on Pane Layout - Pane Layout - Select the options from drop-down list in respective sections.

​

I sometimes move my Console in the top right corner such that it is in line with the Plots, that appear at the bottom right section of the pane.

We will observe that in further illustrations.

RStudio FYIs

For Windows 10

In order to run the code in the RScript,

Click on the Run option at the top-right corner of RScript.

Or

Click Ctrl+Enter from yoour Keyboard.

​

For any comments or Notes that you wish to add to your RScript, start the statement with #. Otherwise, the Console will show error.

For example, #Data Analytics made easy

For a statement to run as command use inverted coma.

For example, "Data Analytics made easy"

RStudio Comments.png

- Understand System Language Interpretation -

Sys.Lang. Interpretation

1. Basic Calcuations in RStudio

RStudio can be used as basic calculator with below simple arithmetic calculatons.

Insert 4 hyphen ( - - - - ) at the end of a comment in RStudio (starting with #) and RStudio will create a quick index of the same (notice the changed at he bottom of the script screen).

R.Calc.png

2. Vector Concatination & Data Type

A sequence of elements which share the same data type is known as vector.

  • We use either <- or = to assign value to a vector.

Observe the changes in the environment when the command is run to create a vector.

Note : R is case sensitive. ​​

Vector.png

There are 4 major types of vector in a data frame : Numeric/Integer, Character, Categorical/Factor & Logical.

Numeric/Integer

Numeric Vector.png

Character Type Vector

Character Vector.png

Categorical/Factor type Vector

It is categorical in nature and needs to be in factor format in R. We will explore this more while working with Data frame.

Categorical Vector.png

Logical type Vector

Logical Vector.png

5. Data Frame

A Data Frame is a combination of Vectors in a tabular format.

In below example we have combined 3 vectors : Character, Categorical & Numeric into a DataFrame Grades, and created Data fraome "Results".

​

Notice the Data frame summarised in Environment : 5 Obs/Observation means Rows & 4 Variables are columns/Vectors.

​

The combination of Vectors makes senece in the Data frame reflecting in Console.

Data Frame.png

6. Conditions

Conditionals are expressions that perform different computations or actions depending on whether a predefined boolean condition is TRUE or FALSE.

​

Below standard logical operations can be used to apply condition:

a == b  Equal To
a != b   Not Equal
a > b    Greater Than
a >= b  Greater Than or Equal To
a < b    Less Than
a <= b  Less Than or Equal To
is.na(a)  is Missing in a

Condition.png

6. Delete or Clear section And Save R Script

Use command rm() to remove vectors or Data set from Environment.

To clear the whole Environment or Console use the broom like icon at the top left corner of the the section.

​

To save the script : Go to File - Save As - name the file & save. (Same as saving any document in your drive).

The script will be saved in R file format.

Clear environment.JPG
Save Script.png
bottom of page