In this exercise you will learn to clean data using the dplyr package. To this end, you will follow through the codes in one of our e-texts, Data Visualization with R. The given example code below is from Chapter 1.2 Cleaning data.

## # A tibble: 87 x 13
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke…    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl… red             33   <NA>  
##  4 Dart…    202   136 none       white      yellow          41.9 male  
##  5 Leia…    150    49 brown      light      brown           19   female
##  6 Owen…    178   120 brown, gr… light      blue            52   male  
##  7 Beru…    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg…    183    84 black      light      brown           24   male  
## 10 Obi-…    182    77 auburn, w… fair       blue-gray       57   male  
## # … with 77 more rows, and 5 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>

Q1 select Keep the variables name, eye_color, and films.

Q2 filter select blonds.

## # A tibble: 19 x 13
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Leia…    150  49   brown      light      brown             19 female
##  2 Beru…    165  75   brown      light      blue              47 female
##  3 Mon …    150  NA   auburn     fair       blue              48 female
##  4 Shmi…    163  NA   black      fair       brown             72 female
##  5 Ayla…    178  55   none       blue       hazel             48 female
##  6 Adi …    184  50   none       dark       blue              NA female
##  7 Cordé    157  NA   brown      light      brown             NA female
##  8 Lumi…    170  56.2 black      yellow     blue              58 female
##  9 Barr…    166  50   black      yellow     blue              40 female
## 10 Dormé    165  NA   brown      light      brown             NA female
## 11 Zam …    168  55   blonde     fair, gre… yellow            NA female
## 12 Taun…    213  NA   none       grey       black             NA female
## 13 Joca…    167  NA   white      fair       blue              NA female
## 14 R4-P…     96  NA   none       silver, r… red, blue         NA female
## 15 Shaa…    178  57   none       red, blue… black             NA female
## 16 Sly …    178  48   none       pale       white             NA female
## 17 Rey       NA  NA   brown      light      hazel             NA female
## 18 Capt…     NA  NA   unknown    unknown    unknown           NA female
## 19 Padm…    165  45   brown      light      brown             46 female
## # … with 5 more variables: homeworld <chr>, species <chr>, films <list>,
## #   vehicles <list>, starships <list>

Q3 filter select female blonds.

## # A tibble: 0 x 13
## # … with 13 variables: name <chr>, height <int>, mass <dbl>, hair_color <chr>,
## #   skin_color <chr>, eye_color <chr>, birth_year <dbl>, gender <chr>,
## #   homeworld <chr>, species <chr>, films <list>, vehicles <list>,
## #   starships <list>

Q4 mutate Convert height in centimeters to feet.

Hint: Divide the length value by 30.48.

Q5 summarize Calculate mean height in feet

Q6 group_by and summarize Calculate mean height by gender.

Hint: Use%>%, the pipe operator. Save the result under a new name, mean_height.

Q7 spread Convert the dataset, mean_height, to a wide dataset.

## # A tibble: 5 x 6
##   mean_wt female hermaphrodite  male  none `<NA>`
##     <dbl>  <dbl>         <dbl> <dbl> <dbl>  <dbl>
## 1    46.3    NA             NA   NA     NA    120
## 2    54.0   165.            NA   NA     NA     NA
## 3    81.0    NA             NA  179.    NA     NA
## 4   140      NA             NA   NA    200     NA
## 5  1358      NA            175   NA     NA     NA

Q8 Hide the messages and the code, but display results of the code from the webpage.

Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.