Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
528 views

Introduction To R Programming PDF

This document provides instructions for Lab 11 on Introduction to R Programming. It outlines 4 steps for students to complete: 1) Install R and RStudio IDE, 2) Install and load packages, 3) Create basic plots using the iris dataset, 4) Submit screenshots of the plots created. Students are asked to take screenshots at several points showing their R code and output plots to submit for grading.

Uploaded by

Casel Law
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
528 views

Introduction To R Programming PDF

This document provides instructions for Lab 11 on Introduction to R Programming. It outlines 4 steps for students to complete: 1) Install R and RStudio IDE, 2) Install and load packages, 3) Create basic plots using the iris dataset, 4) Submit screenshots of the plots created. Students are asked to take screenshots at several points showing their R code and output plots to submit for grading.

Uploaded by

Casel Law
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of Computing

CS-213: Advanced Programming


Class: BSCS-8ABC
Lab 11: Introduction to R Programming

Instructors: Dr. Sidra Sultana and Dr. Sana Qadir


Note: The steps to be completed are labelled as S# and the questions to be answered are
numbered as Q#.

The code required for this lab is in the ​R_Files-1​ folder.

S1: Install ​R​ by clicking on ​download R ​at ​https://www.r-project.org/​ and following the
instructions.
● Get a copy of the folder ​R_Files-1​ from your instructor. The ​.r​ extension is used for
R source/script files.
● Start ​RGui​ and open ​R01_2_1_InstallingR.R​ as shown below:

● Your window should look something like this:

● Starting from the top of the file, navigate to the beginning of each line (that does not start
with ​#​) and press CTRL+R to run it. Try to figure out what each line of code does.
● Once you are done, use CTRL+L to clear the console.

S2: Install RStudio IDE.


● Download and install the free ​RStudio Desktop​ from ​Download the RStudio IDE
● Open up ​R01_2_2_RStudio.R
● Take SCREENSHOT 1 - it should show the entire RStudio window (esp. the ​Plots
pane) when ​plot(iris)​ is run.

S3: Install, load, and use the package manager.


● Open up ​R01_2_3_Packages.R
● Run the line ​install.packages(“pacman”)
● If you get the following message:
WARNING: Rtools is required to build R packages but is not
currently installed. Please download and install the
appropriate version of Rtools before proceeding:
You may need to download and install ​Rtools​ from
https://cran.r-project.org/bin/windows/Rtools/​ before continuing.
● Once ​pacman ​has been installed, run the following two lines:
require(pacman) # Gives a confirmation message.
library(pacman) # No message.
● Confirm ​pacman​ has been loaded successfully:

● Run line 21 to install the following commonly used contributed packages using ​pacman​.
dplyr, GGally, ggplot2, ggthemes, ggvis, httr, lubridate,
plotly, rio, rmarkdown, shiny, stringr, tidyr
Note: this line can be run even without loading ​pacman​.
● You should be able to confirm installation and loading of all these contributed packages:

● Take SCREENSHOT 2 - it should show the entire RStudio window and the four
packages beginning with the letter G should be checked in “Packages”.
● Unload the contributed packages, base packages, and clear the console.

S4: Basic graphics.


● The ​plot ()​ function does basic X-Y plotting in R.
● Open up ​R01_3_1_Plot().R
● The code in this file examines the ​iris ​data frame in the ​datasets​ package that
comes with R.
● The ​iris ​data frame contains measurement data of the sepal (length and width) and
petal (length and width) for three species of iris.This is a very famous dataset and it is
about a hundred years old. It is a great way of exploring what we can do in R.

source: ​http://suruchifialoke.com/img/ML/iris.png
● You may run ​?plot()​ to display information about ​plot()​ in the ​Help​ window.
● Run each line of uncommented code and try to figure out what it does.
● Write a line to create the following plot. Remember to replace ​<CMS ID>​ in title with
your own CMS ID. You can use whatever colour you like best. Also remember to include
the axes titles.

● Take SCREENSHOT 3 - it should show the R code used to generate the plot. Your
screenshot should also include your ​Plots ​window.
● Write three lines to create the following plot. Remember to replace ​<CMS ID>​ in title
with your own CMS ID. You can use whatever colour you like best. Please ensure the
range of values for the x-axis and y-axis are as shown and that the axes intersect at the
origin. The axes labels should also be included.
● Take SCREENSHOT 4 - it should show the R code used to generate the plot. Your
screenshot should also include your ​Plots ​window.
● Write three lines to create the following plot. Remember to replace ​<CMS ID>​ in title
with your own CMS ID.

Hint​: the first plot in the ​Examples​ section of the ​Help​ window can be modified to
create this plot. Remember to take note of what is happening in the ​Environment
window.
● Take SCREENSHOT 5 - it should show the R code used to generate the plot. Your
screenshot should also include the ​Plots​ and window ​Environment ​window.
● You are recommended to copy, run, understand all lines in the ​Examples​ section of the
Help​ window.

SUBMISSION: Instructions
● Convert the following into ​one ​PDF file and upload on the LMS submission link by the
due date:
○ Screenshot 1 to 5.

You might also like