install.packages(c("tidyverse","ggplot2movies",
                   "nycflights13","odbc",
                   "writexl", "openxlsx",
                   "gapminder", "usethis","pacman"))
## Installing packages into '/usr/local/lib/R/site-library'
## (as 'lib' is unspecified)
## Warning in install.packages(c("tidyverse", "ggplot2movies", "nycflights13", :
## installation of package 'odbc' had non-zero exit status
library(tidyverse)
## ── Attaching packages ───────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1     ✓ purrr   0.3.3
## ✓ tibble  2.1.3     ✓ dplyr   0.8.3
## ✓ tidyr   1.0.0     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## ── Conflicts ──────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(nycflights13)
library(openxlsx)
library(gapminder)
library(ggplot2movies)
library(writexl)
#
library(pacman)
p_load(usethis, tidyverse, nycflights13, openxlsx, gapminder, ggplot2movies, writexl)
#
library(pacman)
p_load(ggplot2movies)
head(movies)
## # A tibble: 6 x 24
##   title  year length budget rating votes    r1    r2    r3    r4    r5    r6
##   <chr> <int>  <int>  <int>  <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 $      1971    121     NA    6.4   348   4.5   4.5   4.5   4.5  14.5  24.5
## 2 $100…  1939     71     NA    6      20   0    14.5   4.5  24.5  14.5  14.5
## 3 $21 …  1941      7     NA    8.2     5   0     0     0     0     0    24.5
## 4 $40,…  1996     70     NA    8.2     6  14.5   0     0     0     0     0  
## 5 $50,…  1975     71     NA    3.4    17  24.5   4.5   0    14.5  14.5   4.5
## 6 $pent  2000     91     NA    4.3    45   4.5   4.5   4.5  14.5  14.5  14.5
## # … with 12 more variables: r7 <dbl>, r8 <dbl>, r9 <dbl>, r10 <dbl>,
## #   mpaa <chr>, Action <int>, Animation <int>, Comedy <int>, Drama <int>,
## #   Documentary <int>, Romance <int>, Short <int>
select(movies,title:votes)
## # A tibble: 58,788 x 6
##    title                     year length budget rating votes
##    <chr>                    <int>  <int>  <int>  <dbl> <int>
##  1 $                         1971    121     NA    6.4   348
##  2 $1000 a Touchdown         1939     71     NA    6      20
##  3 $21 a Day Once a Month    1941      7     NA    8.2     5
##  4 $40,000                   1996     70     NA    8.2     6
##  5 $50,000 Climax Show, The  1975     71     NA    3.4    17
##  6 $pent                     2000     91     NA    4.3    45
##  7 $windle                   2002     93     NA    5.3   200
##  8 '15'                      2002     25     NA    6.7    24
##  9 '38                       1987     97     NA    6.6    18
## 10 '49-'17                   1917     61     NA    6      51
## # … with 58,778 more rows
library(pacman)
p_load(ggplot2movies)
head(movies)
## # A tibble: 6 x 24
##   title  year length budget rating votes    r1    r2    r3    r4    r5    r6
##   <chr> <int>  <int>  <int>  <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 $      1971    121     NA    6.4   348   4.5   4.5   4.5   4.5  14.5  24.5
## 2 $100…  1939     71     NA    6      20   0    14.5   4.5  24.5  14.5  14.5
## 3 $21 …  1941      7     NA    8.2     5   0     0     0     0     0    24.5
## 4 $40,…  1996     70     NA    8.2     6  14.5   0     0     0     0     0  
## 5 $50,…  1975     71     NA    3.4    17  24.5   4.5   0    14.5  14.5   4.5
## 6 $pent  2000     91     NA    4.3    45   4.5   4.5   4.5  14.5  14.5  14.5
## # … with 12 more variables: r7 <dbl>, r8 <dbl>, r9 <dbl>, r10 <dbl>,
## #   mpaa <chr>, Action <int>, Animation <int>, Comedy <int>, Drama <int>,
## #   Documentary <int>, Romance <int>, Short <int>
select(movies,Action:Short)
## # A tibble: 58,788 x 7
##    Action Animation Comedy Drama Documentary Romance Short
##     <int>     <int>  <int> <int>       <int>   <int> <int>
##  1      0         0      1     1           0       0     0
##  2      0         0      1     0           0       0     0
##  3      0         1      0     0           0       0     1
##  4      0         0      1     0           0       0     0
##  5      0         0      0     0           0       0     0
##  6      0         0      0     1           0       0     0
##  7      1         0      0     1           0       0     0
##  8      0         0      0     0           1       0     1
##  9      0         0      0     1           0       0     0
## 10      0         0      0     0           0       0     0
## # … with 58,778 more rows

Q2

movies %>% select(starts_with("r"))
## # A tibble: 58,788 x 12
##    rating    r1    r2    r3    r4    r5    r6    r7    r8    r9   r10 Romance
##     <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>   <int>
##  1    6.4   4.5   4.5   4.5   4.5  14.5  24.5  24.5  14.5   4.5   4.5       0
##  2    6     0    14.5   4.5  24.5  14.5  14.5  14.5   4.5   4.5  14.5       0
##  3    8.2   0     0     0     0     0    24.5   0    44.5  24.5  24.5       0
##  4    8.2  14.5   0     0     0     0     0     0     0    34.5  45.5       0
##  5    3.4  24.5   4.5   0    14.5  14.5   4.5   0     0     0    24.5       0
##  6    4.3   4.5   4.5   4.5  14.5  14.5  14.5   4.5   4.5  14.5  14.5       0
##  7    5.3   4.5   0     4.5   4.5  24.5  24.5  14.5   4.5   4.5  14.5       0
##  8    6.7   4.5   4.5   4.5   4.5   4.5  14.5  14.5  14.5   4.5  14.5       0
##  9    6.6   4.5   4.5   4.5   0     0     0    34.5  14.5   4.5  24.5       0
## 10    6     4.5   0     4.5   4.5   4.5  44.5  14.5   4.5   4.5   4.5       0
## # … with 58,778 more rows
movies %>% select(starts_with("m"))
## # A tibble: 58,788 x 1
##    mpaa 
##    <chr>
##  1 ""   
##  2 ""   
##  3 ""   
##  4 ""   
##  5 ""   
##  6 ""   
##  7 "R"  
##  8 ""   
##  9 ""   
## 10 ""   
## # … with 58,778 more rows

Q3

irisImperial <- iris %>% mutate(Species=toupper(Species),
                                Sepal.Width=Sepal.Width/2.5,
                                Sepal.Width=Sepal.Width/2.5,
                                Petal.Width=Petal.Width/2.5,
                                Petal.Width=Petal.Width/2.5)
head(irisImperial)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1       0.560          1.4       0.032  SETOSA
## 2          4.9       0.480          1.4       0.032  SETOSA
## 3          4.7       0.512          1.3       0.032  SETOSA
## 4          4.6       0.496          1.5       0.032  SETOSA
## 5          5.0       0.576          1.4       0.032  SETOSA
## 6          5.4       0.624          1.7       0.064  SETOSA