STA2020 Lab 1: R and RStudio
This lab will test your understanding of the basics of R and RStudio. Note that where words are in italics
or included between quotation marks (or both) it requires input from you e.g. “your name” means that
you would type your name. If you are working on your own laptop/PC, you need to have installed R and
RStudio before attempting to do this lab.
Instructions:
1) Make sure that you have downloaded the dataset ‘[Link]’ and the pdf ‘R and RStudio – lab 1’
2) Save it to your desktop or downloads folder.
3) Make sure you have opened RStudio.
4) Set your working directory to wherever you have saved the [Link] file by using: Session – Set
working directory – Choose directory and navigate to wherever you have saved the dataset for
this lab.
5) Insert a new R Script, using File – New File – R Script OR by clicking the white page with the
green + button and selecting R Script
6) Type the following in the first few lines of your RScript:
# My name is “your name”
# This is my first R and RStudio lab
# Todays date is “todays date”
7) Import the [Link] dataset into RStudio by clicking on it and selecting ‘Import dataset’ and then
selecting ‘Import’
8) Type attach(lab1) into your script and then select ‘Run’ to attach the dataset to your workspace
in RStudio
9) Type mean(domestic) into your script and then select ‘Run’ to compute the mean of domestic
US profits
10) Type median(nonfin) into your script and then select ‘Run’ to compute the median of
nonfinancial US profits
11) Type var(corpprof) into your script and then select ‘Run’ to compute the variance of adjusted
corporate US profits
12) Type hist(restworld) into your script and then select ‘Run’ to plot a histogram of the rest of the
world’s profits
13) Type summary(nonfin) into your script and then select ‘Run’ to compute a 6-number summary
of the nonfinancial US profits
14) Type plot(year, corpprof) into your script and then select ‘Run’ to plot the corporate US profits
against year
15) Type boxplot(domestic) into your script and then select ‘Run’ to plot a boxplot of the domestic
US profits