Description
ITMD/ITMS/STAT 514 Homework 1
Your Team Members’ Name
Due Date 9/12
# If you don't already have the tidyverse library installed,
# you will need to type install.packages("tidyverse") into the Console
library(tidyverse)
1. Changing the author field and file name. (5 points)
(a) Change the author:
field on the Rmd document
(b) Rename this file to “HW1_YourGroupNumberHere.Rmd”, where YourGroupNumberHere is changed to your group number (e.g. Group1).
2. Hello World! (5 points)
Here’s an R code chunk that prints the text ‘Hello world!’.
print("Hello world!")
## [1] "Hello world!"
(a) Modify the code chunk below to print your team members’ name
# Edit me
3. Creating a numeric vector (20 points)
We just learned about the c()
operator, which forms a vector from its arguments. If we’re trying to build a vector containing a sequence of numbers, there are several useful functions at our disposal. These are the colon operator :
and the sequence function seq()
.
:
Colon operator:
1:10 # Numbers 1 to 10
## [1] 1 2 3 4 5 6 7 8 9 10
127:132 # Numbers 127 to 132
## [1] 127 128 129 130 131 132
seq
function: seq(from, to, by)
seq(1,10,1) # Numbers 1 to 10
## [1] 1 2 3 4 5 6 7 8 9 10
seq(1,10,2) # Odd numbers from 1 to 10
## [1] 1 3 5 7 9
seq(2,10,2) # Even numbers from 2 to 10
## [1] 2 4 6 8 10
To learn more about a function, type
?functionname
into your console. E.g.,?seq
pulls up a Help file with the R documentation for theseq
function.
(a) Use :
to output the sequence of numbers from 3 to 12 (5 points)
# Edit me
(b) Use seq()
to output the sequence of numbers from 3 to 30 in increments of 3 (5 points)
# Edit me
(c) Save the sequence from (a) as a variable x
, and the sequence from (b) as a variable y
. Output their product x*y
(10 points)
# Edit me
4. Cars data (70 points)
We’ll look at data frame and plotting in much more detail in later classes. For a previous of what’s to come, here’s a very basic example.
For this example we’ll use a very simple dataset. The cars
data comes with the default installation of R. To see the first few rows of the data, just type head(cars)
.
head(cars)
## speed dist
## 1 4 2
## 2 4 10
## 3 7 4
## 4 7 22
## 5 8 16
## 6 9 10
(a) Calculate the average and standard deviation of speed
(5 points)
# Edit me
Type your answer here
(b) Calculate the average and standard deviation of dist
(5 points)
# Edit me
Type your answer here
(c) Calulate the average and standard deviation of dist
when speed
is greater than 15. (5 points)
# Edit me
Type your answer here
(d) Calulate the average and standard deviation of dist
when speed
is less than and equal to 15. (5 points)
# Edit me
Type your answer here
(e) Calulate the average and standard deviation of dist
when speed
is greater than 12 and less than 19. (10 points)
# Edit me
Type your answer here
(f) Produce a histogram of speed
with 5 bins. Please illustrate your observation from the output. (10 points)
# Edit me
(g) Produce a histogram of dist
with 20 bins. Please illustrate your observation from the output. (10 points)
# Edit me
(h) Use the boxplot
function to create a boxplot of speed
. Please illustrate your observation from the output. (10 points)
# Edit me
(i) Use the boxplot
function to create a boxplot of dist
. Please illustrate your observation from the output. (10 points)
# Edit me