select Keep the variables name, hair_color, and films.filter select blonds.filter select female blonds.mutate Convert height from centimeters to feet.summarize Calculate mean height.group_by Calculate mean BMI.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>
select Keep the variables name, hair_color, and films.## # A tibble: 87 x 3
## name hair_color films
## <chr> <chr> <list>
## 1 Luke Skywalker blond <chr [5]>
## 2 C-3PO <NA> <chr [6]>
## 3 R2-D2 <NA> <chr [7]>
## 4 Darth Vader none <chr [4]>
## 5 Leia Organa brown <chr [5]>
## 6 Owen Lars brown, grey <chr [3]>
## 7 Beru Whitesun lars brown <chr [3]>
## 8 R5-D4 <NA> <chr [1]>
## 9 Biggs Darklighter black <chr [1]>
## 10 Obi-Wan Kenobi auburn, white <chr [6]>
## # … with 77 more rows
filter select blonds.## # A tibble: 3 x 13
## name height mass hair_color skin_color eye_color birth_year gender homeworld
## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr>
## 1 Luke… 172 77 blond fair blue 19 male Tatooine
## 2 Anak… 188 84 blond fair blue 41.9 male Tatooine
## 3 Fini… 170 NA blond fair blue 91 male Coruscant
## # … with 4 more variables: species <chr>, films <list>, vehicles <list>,
## # starships <list>
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>
mutate Convert height from centimeters to feet.## # A tibble: 87 x 13
## name height mass hair_color skin_color eye_color birth_year gender
## <chr> <dbl> <dbl> <chr> <chr> <chr> <dbl> <chr>
## 1 Luke… 5.64 77 blond fair blue 19 male
## 2 C-3PO 5.48 75 <NA> gold yellow 112 <NA>
## 3 R2-D2 3.15 32 <NA> white, bl… red 33 <NA>
## 4 Dart… 6.63 136 none white yellow 41.9 male
## 5 Leia… 4.92 49 brown light brown 19 female
## 6 Owen… 5.84 120 brown, gr… light blue 52 male
## 7 Beru… 5.41 75 brown light blue 47 female
## 8 R5-D4 3.18 32 <NA> white, red red NA <NA>
## 9 Bigg… 6.00 84 black light brown 24 male
## 10 Obi-… 5.97 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>
summarize Calculate mean height.## # A tibble: 1 x 1
## mean_ht
## <dbl>
## 1 174.
group_by Calculate mean BMI.## # A tibble: 1 x 5
## female hermaphrodite male none `<NA>`
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 165. 175 179. 200 120
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.