Problem Set # 1

Jenine Massat

date()
## [1] "Wed Sep 06 14:30:03 2017"

Due Date: September 7, 2017

Total Points: 14

1 Tweak each of the following R commands so that they run correctly (6)
First error: “Error in library(tidyverse) : there is no package called ‘tidyverse’.
Fix: Had to install tidyverse by going to packages, install, and typing”tidyverse" into the pop-up box.
Second error: “ggplot2 doesn’t know how to deal with date of class uneval”.
Fix: Change “ggplot(dota = mpg”… to “ggplot(data = mpg”…
Third error: “Error in fliter(mpg, cyl = 8) : could not find function”fliter“.”
Fix: Change it to “filter(mpg, cyl = 8)”.
Fourth error: “Error: cyl (cyl = 8) must not be named, do you need ==?”
Fix: Yes. I do need “cyl == 8”.
Fifth error: “Error in filter(diamond, carat > 3) : object ‘diamond’ not found’”.
Fix: Add an “s” to diamond.

library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
ggplot(data = mpg, aes(x = displ, y = hwy)) +
  geom_point()

filter(mpg, cyl == 8)
## # A tibble: 70 x 11
##    manufacturer              model displ  year   cyl      trans   drv
##           <chr>              <chr> <dbl> <int> <int>      <chr> <chr>
##  1         audi         a6 quattro   4.2  2008     8   auto(s6)     4
##  2    chevrolet c1500 suburban 2wd   5.3  2008     8   auto(l4)     r
##  3    chevrolet c1500 suburban 2wd   5.3  2008     8   auto(l4)     r
##  4    chevrolet c1500 suburban 2wd   5.3  2008     8   auto(l4)     r
##  5    chevrolet c1500 suburban 2wd   5.7  1999     8   auto(l4)     r
##  6    chevrolet c1500 suburban 2wd   6.0  2008     8   auto(l4)     r
##  7    chevrolet           corvette   5.7  1999     8 manual(m6)     r
##  8    chevrolet           corvette   5.7  1999     8   auto(l4)     r
##  9    chevrolet           corvette   6.2  2008     8 manual(m6)     r
## 10    chevrolet           corvette   6.2  2008     8   auto(s6)     r
## # ... with 60 more rows, and 4 more variables: cty <int>, hwy <int>,
## #   fl <chr>, class <chr>
filter(diamonds, carat > 3)
## # A tibble: 32 x 10
##    carat     cut color clarity depth table price     x     y     z
##    <dbl>   <ord> <ord>   <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
##  1  3.01 Premium     I      I1  62.7    58  8040  9.10  8.97  5.67
##  2  3.11    Fair     J      I1  65.9    57  9823  9.15  9.02  5.98
##  3  3.01 Premium     F      I1  62.2    56  9925  9.24  9.13  5.73
##  4  3.05 Premium     E      I1  60.9    58 10453  9.26  9.25  5.66
##  5  3.02    Fair     I      I1  65.2    56 10577  9.11  9.02  5.91
##  6  3.01    Fair     H      I1  56.1    62 10761  9.54  9.38  5.31
##  7  3.65    Fair     H      I1  67.1    53 11668  9.53  9.48  6.38
##  8  3.24 Premium     H      I1  62.1    58 12300  9.44  9.40  5.85
##  9  3.22   Ideal     I      I1  62.6    55 12545  9.49  9.42  5.92
## 10  3.50   Ideal     H      I1  62.8    57 12587  9.65  9.59  6.03
## # ... with 22 more rows

2 Assign to an object x the sum of 3 and 5. Find the square root of the sum (4).

x <- 3+5
sqrt(sum(x))
## [1] 2.828427

3 Create a vector h with the following elements and table the count frequencies: 2 4 0 3 1 0 0 1 2 0. Hint: use the table() function (4).

h <- c(2, 4, 0, 3, 1, 0, 0, 1, 2, 0)
table(h)
## h
## 0 1 2 3 4 
## 4 2 2 1 1