Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Assignment #0

Introduction to R
Due: Sept. 2 before class
(40 pts. Total)
Link to the appendix titled Using-R in our online textbook at https://www.otexts.org/fpp/using-r and
follow the instructions and links provided to:
a. Install R on your computer
b. Install RStudio on your computer
c. Install the package fpp on your RStudio
d. Download the dataset tute1.csv to your computer, and then import it into R-Studio
e. Follow the detailed instructions for the 16 steps in the Getting Started with R section of the
Using Rappendix.

Read and execute the laboratory called Introduction to R in ISLR on pages 42-51. As you practice the R
commands in the laboratory answer the following questions:
1. Write an R command to create the following matrix:
1 3 5
(7 2 3)
9 8 0
Execute the following sequence of commands:
> x <- rnorm(10)
> mean(x)
> var(x)
> y <- rnorm(10)
> mean(y)
> var(y)
2. Why did you not get the same values for the mean and variance of and if they were
obtained using the same command sequence?

Now execute the following sequence of commands:


> set.seed(2567)
> x <- rnorm(10)
> mean(x)
> var(x)
> set.seed(2567)
> y <- rnorm(10)
> mean(y)
> var(y)
3. Why did you now get the same values for the mean and variance of and ?
4. Define = /8 sin() and use R Studio to plot vs for = 1, 2, , 20. Then save this plot
as a jpeg file and include it in your report.

Generate the matrix as follows:


> B <- matrix(10:25,4,4)
5. Write an R command to extract the matrix shown below from the matrix generated above:
15 23
(16 24)
17 25
Copy the files Auto.data and Auto.csv into your homework project folder and answer the
following questions:
6. What is the name of the car in record number 38 of the Auto data set?
7. Use the pairs() function in R to create a scatterplot matrix showing the scatterplots of the
variables mpg, horsepower, weight and acceleration in the Auto dataset. Include
the command and the resulting plot in your report.
8. By looking at the plots produced in question (7) indicate what pairs of variables seem to be
positively correlated? Which pairs of variables seem to be negatively correlated?

You might also like